繁体   English   中英

Nodemailer连接超时错误

[英]Nodemailer connection timeout error

我正在使用 nodemailer 模块从我的 nodejs 应用程序发送邮件。 我收到错误:连接 ETIMEDOUT xxx.xxx.xx.xxx:465 任何人都可以帮我解决这个问题。 我在这里粘贴我的代码。

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

这可能是防火墙问题。 我在 Ubuntu(数字海洋服务器)中遇到了类似的问题。 尝试解决此问题 3 天,也尝试使用 auth2,尝试使用 ufw inactive 命令使用非活动防火墙,但没有运气。 最后,我检查了 Digital Ocean 管理面板并为 droplet 创建了防火墙。 通过在防火墙设置中启用 TCP 入站和出站解决了问题。

你有没有看过这个答案

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

所以你有两个选择:

  • 使用 OAuth

  • 降低您的帐户安全性

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

我今天遇到了同样的问题,找到了这个文档......

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

必须通过在登录 gmail 时访问 url 从服务器执行验证程序。

希望它可以帮助其他人。

此错误的唯一原因是:

  1. 安全性较低的应用程序:您必须从您的 Gmail 帐户启用“安全性较低的应用程序”。

  2. 使用 OAuth

除了已经提到的对https://nodemailer.com/usage/using-gmail/信息的引用之外,在我的情况下,Internet 路由器(Speedport W724V)仍然是一个问题。 这会保留所有允许的 SMTP 服务器的列表。 在我相应地扩展了列表之后,它工作得很好。 我必须对smtp.ethereal.email做同样的事情。

我不确定是否应该发布此答案,但我在使用 GMAIL 时遇到了同样的问题,而且我的错误背后的原因是连接到 vpn。 我禁用了它,现在它可以工作了。

我正在使用应用程序密码

打开端口入站出站规则 587 或其他,无论您在服务器 aws/google 等上使用哪个。

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

暂无
暂无

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

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