使用 Nodemailer 从 Zohomail 发送邮件时出现连接超时错误

Connection timeout error when sending mail from Zohomail using Nodemailer

下面是我的节点 app.js 代码。使用这些设置,我收到连接超时错误。知道我在这里缺少什么吗?

var nodemailer = require("nodemailer");

var transporter = nodemailer.createTransport({
  host: 'smtp.zoho.com',
    port: 465,
    secure: true, // use SSL
    auth: {
        user: '<myemail@example.com>',
        pass: '<myemailpassword>'
    }
});

var mailOptions = {
  from: "<fromemail@example.com>",
  to: "<toemail@example.com>",
  subject: "Hello",
  generateTextFromHTML: true,
  html: { path: './tmpl.html' }
};

transporter.sendMail(mailOptions, function(error, response) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
  transporter.close();
});

显示错误

{ Error: Connection timeout
    at SMTPConnection._formatError (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:557:19)
    at SMTPConnection._onError (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:530:20)
    at Timeout._connectionTimeout.setTimeout (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:248:18)
    at ontimeout (timers.js:380:14)
    at tryOnTimeout (timers.js:244:5)
    at Timer.listOnTimeout (timers.js:214:5) code: 'ETIMEDOUT', command: 'CONN' }

谁能帮帮我?

一些云提供商禁用了 465 和 587 等端口,请尝试使用端口 2525 而不是 465。

更新

由于您为此使用 Cloud9,我发现他们已阻止来自其服务器的所有出站 smtp 调用。如果您仍然需要发送,则需要选择其他云提供商或使用他们推荐的服务之一。

https://community.c9.io/t/how-can-i-send-email-from-my-app/1262