Sending mail in node.js using nodemailer

try https://github.com/nodemailer/nodemailer/issues/406

add tls: { rejectUnauthorized: false } to your transporter constructor options

p.s It's not a good idea to post your mail server address, if it's a real one


To allow to send an email via “less secure apps”, go to the link and choose “Turn on”.

(More info about less secure apps)

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

var mailAccountUser = '<YOUR_ACCOUNT_USER>'
var mailAccountPassword = '<YOUR_ACCOUNT_PASS>'

var fromEmailAddress = '<FROM_EMAIL>'
var toEmailAddress = 'TO_EMAIL'

var transport = nodemailer.createTransport(smtpTransport({
    service: 'gmail',
    auth: {
        user: mailAccountUser,
        pass: mailAccountPassword
    }
}))

var mail = {
    from: fromEmailAddress,
    to: toEmailAddress,
    subject: "hello world!",
    text: "Hello!",
    html: "<b>Hello!</b><p><a href=\"http://www.yahoo.com\">Click Here</a></p>"
}

transport.sendMail(mail, function(error, response){
    if(error){
        console.log(error);
    }else{
        console.log("Message sent: " + response.message);
    }

    transport.close();
});