I am newbie to nodejs and learning by implementing some examples.I am trying to send an email using nodemailer using below code:
var smtpConfig = {
host: 'smtp.gmail.com',
port: 465,
secure: true, // use SSL
auth: {
user: 'xxx@gmail.com',
pass: 'xxx@a'
}
};
var transporter = nodemailer.createTransport(smtpConfig);
// setup e-mail data with unicode symbols
var mailOptions = {
from: '"Fred Foo ?" <xxx@gmail.com>', // sender address
to: 'xxx@gmail.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ?', // plaintext body
html: '<b>Hello world ?</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
}
I am getting following error when i run:
Can anyone let me know where am i doing wrong.
EDIT:
Verified connection configuration using below code:
// verify connection configuration
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log('Server is ready to take our messages');
}
});
The verification returns error- Error: connect ECONNREFUSED
Checked these-
- Not a firewall issue, as it was disabled
- Enabled- Access for less secure apps
Thanks, WH