无法使用nodemailer从heroku发送邮件

时间:2018-07-28 21:45:57

标签: javascript node.js heroku nodemailer

这是我尝试从已部署的应用程序发送电子邮件时在heroku上遇到的错误。

{ Error: Connection timeout
2018-07-28T21:37:39.586059+00:00 app[web.1]:     at SMTPConnection._formatError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:606:19)
2018-07-28T21:37:39.586061+00:00 app[web.1]:     at SMTPConnection._onError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:579:20)
2018-07-28T21:37:39.586063+00:00 app[web.1]:     at Timeout._connectionTimeout.setTimeout (/app/node_modules/nodemailer/lib/smtp-connection/index.js:261:18)
2018-07-28T21:37:39.586066+00:00 app[web.1]:     at ontimeout (timers.js:365:14)
2018-07-28T21:37:39.586067+00:00 app[web.1]:     at tryOnTimeout (timers.js:237:5)
2018-07-28T21:37:39.586069+00:00 app[web.1]:     at Timer.listOnTimeout (timers.js:207:5) code: 'ETIMEDOUT', command: 'CONN' }

我正在使用4.6.7版的nodemailer,下面是代码:

'use strict';
const nodemailer = require('nodemailer');

module.exports = {
   sendMail: function(email) {
      console.log(email)
      // create reusable transporter object using the default SMTP transport
      let transporter = nodemailer.createTransport(sails.config.connections.mailer);

      // setup email data with unicode symbols
      let mailOptions = {
        from: '"Medico " <test@testgmail.com>', // sender address
        to: email, // list of receivers
        subject: 'Test', // Subject line
        text: 'Hello world?', // plain text body
        html: 'Hello world?' // html body
      };

      // send mail with defined transport object
      transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
            return console.log(error);
        }
        console.log('Message sent: %s', info.messageId);
        // Preview only available when sending through an Ethereal account
        console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
      });
   }
}

我正在使用Google生成的应用密码,当我在本地运行该密码时效果很好,但是在heroku上会抛出错误。

我在做什么错了?

0 个答案:

没有答案