Nodemailer connection timeout error

我怕爱的太早我们不能终老 提交于 2020-01-13 06:58:53

问题


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

回答1:


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




回答2:


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



回答3:


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.




回答4:


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




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/42387451/nodemailer-connection-timeout-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!