简体   繁体   中英

Nodemailer connection timeout error

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!'
});

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.

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

// 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
  });

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.

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

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 .

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

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

主机:主机,secureConnection:假,端口:465,安全:真,身份验证:{用户:用户,通过:通过}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM