I'm trying to send gmail using nodemailer. Here is my code.
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '<sender@gmail.com>',
pass: '<password>'
}
});
var mailOptions = {
from: '<sender@gmail.com>',
to: '<receiver@gmail.com>',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
But I always got this error.
{ Error: Connection timeout
at SMTPConnection._formatError (E:\Work\Web\GatherSense\gather-sense-backend\node_modules\nodemailer\lib\smtp-connection\index.js:771:19)
at SMTPConnection._onError (E:\Work\Web\GatherSense\gather-sense-backend\node_modules\nodemailer\lib\smtp-connection\index.js:757:20)
at Timeout._connectionTimeout.setTimeout (E:\Work\Web\GatherSense\gather-sense-backend\node_modules\nodemailer\lib\smtp-connection\index.js:229:22)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10) code: 'ETIMEDOUT', command: 'CONN' }
I've spent much time and tried in many ways such as allowing secure less apps and turning off firewalls. But always get the same error. Please help me and thank you.