【问题标题】:Sending email with node and express使用节点和快递发送电子邮件
【发布时间】:2018-06-02 03:28:29
【问题描述】:

所以我有这个小型节点服务器,我尝试发送这样的电子邮件

app.post('/messaggio', function(req, res) {
   var textMessage = req.body.message;
   var transporter = nodemailer.createTransport({
       Service : 'Gmail',
       auth : {
          user : 'myemail01@gmail.com',
          pass : 'mypassword'
       }
   });

   var mailOptions = {
      from: 'myemail@gmail.com',
      to : 'receiver3@gmail.com',
      subject : "My SUBJECT",
      text : textMessage
   }

  transporter.sendMail(mailOptions, function(error, info) {
      if(error) {
        console.log(error);
      }
      else {        
        console.log("message sent");
      }
  });
}); 

我在 heroku 上部署了它,但在 /messaggio 请求时,我在 heroku 日志中收到了以下消息:

app[web.1]: { 错误:连接 ECONNREFUSED 127.0.0.1:587

app[web.1]: 在 Object._errnoException (util.js:1024:11)

app[web.1]:在 _exceptionWithHostPort (util.js:1046:20)

app[web.1]:在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)

app[web.1]:代码:'ECONNECTION',

app[web.1]: errno: 'ECONNREFUSED',

app[web.1]: 系统调用: 'connect',

app[web.1]:地址:'127.0.0.1',

app[web.1]:端口:587,

app[web.1]: 命令:'CONN' }

谁能帮助我?提前致谢

【问题讨论】:

标签: node.js express nodemailer


【解决方案1】:

试试

var transporter = nodeMailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
        user: 'youremail@gmail.com',
        pass: 'password'
    }
});

【讨论】:

    猜你喜欢
    • 2016-09-07
    • 1970-01-01
    • 2016-01-24
    • 2017-01-25
    • 2022-07-27
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    相关资源
    最近更新 更多