2

我正在尝试通过放入我 server.js 的这段代码使用 nodemailer 发送一些电子邮件

服务器.js

var smtpTransport = mailer.createTransport("SMTP", {
    service: "gmail",
    auth: {
        user: "abc@gmail.com",
        pass: "pass"
    }
});

var mail = {
    from: "Contact <abc@gmail.com>",
    to: "abc@gmail.com",
    Subject: "Test sujet",
    text: "test text",
    html: "<b>Test text</b>"
}

smtpTransport.sendMail(mail, function(err, res){
    console.log(err, "Message sent: ");
    smtpTransport.close();
})

但是,当我连接 server.js 时,我收到以下错误消息:

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' } 'Message sent: '

编辑:参考this,我也尝试检查我的ssl连接openssl s_client -connect smtp.gmail.com:465(它正在工作)。

我该如何解决?

4

2 回答 2

5

我遇到了同样的错误,并点击了 nfreeze 在评论中发送的链接。对于您的代码,它看起来像这样。我希望这有帮助!

  var nodemailer = require('nodemailer');
  var smtpTransport = require('nodemailer-smtp-transport');

  var transporter = nodemailer.createTransport(smtpTransport({
  service: 'Gmail',
  auth: { user: 'abc@gmail.com',
        pass: 'pass' }
  }));

  transporter.sendMail({
    from: 'Contact <abc@gmail.com>',
    to: "abc@gmail.com",
    subject: 'Test sujet',
    text: "test text",
    html: "<b>Test text</b>"
  }, function (error, response) {
    //Email not sent
    if (error) {
      res.end("Email send Falied");
    }
    //email send sucessfully
    else {
      console.log(response);
    }
  });
于 2014-07-29T01:29:36.323 回答
-5

您可以删除“SMTP”选项。

于 2014-07-27T02:44:44.093 回答