简体   繁体   English

Nodemailer连接超时错误

[英]Nodemailer connection timeout error

I am using nodemailer module to send mail from my nodejs application.我正在使用 nodemailer 模块从我的 nodejs 应用程序发送邮件。 I am getting Error: connect ETIMEDOUT xxx.xxx.xx.xxx:465 .我收到错误:连接 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).我在 Ubuntu(数字海洋服务器)中遇到了类似的问题。 Tried to fix the issue for 3 days, tried using auth2 also, tried with inactive firewall using ufw inactive command, but no luck.尝试解决此问题 3 天,也尝试使用 auth2,尝试使用 ufw inactive 命令使用非活动防火墙,但没有运气。 Finally I checked Digital Ocean admin panel and created firewall for the droplet.最后,我检查了 Digital Ocean 管理面板并为 droplet 创建了防火墙。 Problem solved by enabling TCP inbound and outbound in firewall settings.通过在防火墙设置中启用 TCP 入站和出站解决了问题。

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 ).事实证明,为了让 Google 现在授权第三方服务器通过 SMTP 访问您的帐户,如果您想使用用户名/密码(更多信息在这里),您必须在您的 gmail 帐户上启用“安全性较低的应用程序”。

So you have two option:所以你有两个选择:

  • use OAuth使用 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/ https://nodemailer.com/usage/using-gmail/

Had to do a capcha process from the server, by visiting a url while logged into gmail.必须通过在登录 gmail 时访问 url 从服务器执行验证程序。

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.安全性较低的应用程序:您必须从您的 Gmail 帐户启用“安全性较低的应用程序”。

  2. Use OAuth使用 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.除了已经提到的对https://nodemailer.com/usage/using-gmail/信息的引用之外,在我的情况下,Internet 路由器(Speedport W724V)仍然是一个问题。 This keeps a list of all allowed SMTP servers.这会保留所有允许的 SMTP 服务器的列表。 After I had extended the list accordingly, it worked perfectly.在我相应地扩展了列表之后,它工作得很好。 I had to do the same with smtp.ethereal.email .我必须对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.我不确定是否应该发布此答案,但我在使用 GMAIL 时遇到了同样的问题,而且我的错误背后的原因是连接到 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.打开端口入站出站规则 587 或其他,无论您在服务器 aws/google 等上使用哪个。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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