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

时间:2017-05-03 06:36:44

标签: node.js smtp nodemailer zoho cloud9

下面是我的Node 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' }

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:4)

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

<强>更新

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

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