3

I am using nodemailer module to send mail from my nodejs application. I am getting Error: connect ETIMEDOUT xxx.xxx.xx.xxx:465. Can any one help me in solving this. Here I am pasting my code.

var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
    user: 'my_mail_id@gmail.com',
    pass: 'my_gmail_password'
}
});

console.log('created');
transporter.sendMail({
from: 'my_mail_id@gmail.com',
  to: 'my_mail_id@gmail.com',
  subject: 'hello world!',
  text: 'hello world!'
});
naik3
  • 319
  • 2
  • 8
  • 22

9 Answers9

4

This may be firewall problem. I faced similar problem in Ubuntu (Digital Ocean server). Tried to fix the issue for 3 days, tried using auth2 also, tried with inactive firewall using ufw inactive command, but no luck. Finally I checked Digital Ocean admin panel and created firewall for the droplet. Problem solved by enabling TCP inbound and outbound in firewall settings.

tiron
  • 41
  • 2
2

Have you looked at this answer.

It turns out that in order for Google to authorize a third party server to access your account via SMTP now, you have to enable “Less Secure Apps” on your gmail account, if you want to use username/password (more info here).

So you have two option:

  • use OAuth

  • make your account less secure

Community
  • 1
  • 1
Ivan Vasiljevic
  • 5,478
  • 2
  • 30
  • 35
  • Hi Ivan, thanks for replying. I tried second option(less secure). But still same error. – naik3 Feb 22 '17 at 11:38
  • Just for checking , I have changed this **nodemailer.createTransport({** to **nodemailer.createTransport({"SMTP"**. I am getting this error **TypeError: Cannot create property 'mailer' on string 'SMTP'** – naik3 Feb 22 '17 at 12:09
  • It take some time until new settings is applied. So you can try after an hour. That was my experience at least. – Ivan Vasiljevic Feb 22 '17 at 12:26
  • Also look at this official tutorial for gmail - https://nodemailer.com/usage/using-gmail . You might have issue with captcha also. – Ivan Vasiljevic Feb 22 '17 at 15:24
  • 1
    Thanks Ivan. But Still i am getting the same error. – naik3 Feb 24 '17 at 18:29
1

I'm not sure if should be posting this answer but I've faced the same problem while using GMAIL and the reason behind the error for me was being connected to a vpn. I disabled it and now it works.

I'm using an application password

Ke1vans
  • 106
  • 7
0
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
    service: 'Hotmail',
    auth: {
        user: "username",
        pass: "paasweord"
    }
});

console.log('SMTP Configured');

// Message object
  var message = {

  // sender info
  from: 'abc@hotmail.com',

   // Comma separated list of recipients
  to: req.query.to //'aadityashukla9@hotmail.com',

   // Subject of the message
  subject:req.query.subject //'Nodemailer is unicode friendly ✔', 

  // plaintext body
   text: req.query.text //'Hello to myself!',

  // HTML body
  /*  html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
     '<p>Here\'s a nyan cat for you as an embedded attachment:<br/></p>'*/
  };

  console.log('Sending Mail');
  transport.sendMail(message, function(error){
  if(error){
  console.log('Error occured');
  console.log(error.message);
  return;
  }
   console.log('Message sent successfully!');


//transport.close(); // close the connection pool
  });
aaditya
  • 555
  • 7
  • 19
  • Hi, thanks for replying, I am getting this error TypeError: Cannot create property 'mailer' on string 'SMTP' – naik3 Feb 24 '17 at 18:26
  • I think you are using older version of node. Please, check official resource for more details: https://nodemailer.com/smtp/ – aaditya Feb 25 '17 at 18:43
0

I experienced this same issue today, found this documentation...

https://nodemailer.com/usage/using-gmail/

Had to do a capcha process from the server, by visiting a url while logged into gmail.

Hopefully it helps others.

0

Besides the already mentioned reference to the information at https://nodemailer.com/usage/using-gmail/, in my case the Internet Router (Speedport W724V) was still a problem. This keeps a list of all allowed SMTP servers. After I had extended the list accordingly, it worked perfectly. I had to do the same with smtp.ethereal.email.

Daniel
  • 459
  • 6
  • 16
0

open port inbound outbound rule 587 or others, whichever you are using on server aws/google etc.

-1

There are the only reasons of this error:

  1. Less Secure Apps: you have to Enable the "Less Secure Apps" from your Gmail account.

  2. Use OAuth

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Osama Bari
  • 597
  • 3
  • 15
-1

host: host, secureConnection: false, port: 465, secure: true, auth: { user: user, pass: pass }

muhyidin
  • 189
  • 2
  • 7