Nodemailer,Heroku,Gmail,无效登录 - 在本地运行

Tru*_*acy 7 javascript heroku node.js nodemailer

我在过去几周一直遇到这个问题,它每次都在本地工作,但是一旦我将它部署到我的heroku服务器,它就会给我一个invalid login错误.我已经进入帐户并且可以访问不太安全的应用程序.凭据是正确的,并且每次都在localhost上运行.有什么我想念的吗?

quickSendMail: function(routeBody, callback) {
//configuring the nodemailer for email notifications
  var smtpConfig = {
          host: 'smtp.gmail.com',
          port: 465,
          secure: true, // use SSL
          auth: {
              user: 'mysmtpemail123',
              pass: '******'
            }
        };

  var mailOptions = {
          from: 'SageStorm Site <mysmtpemail123@gmail.com>',
          to: ['my email'],
          subject: routeBody.subject,
          html: 'my message'
        };

  var transporter = nodemailer.createTransport(smtpConfig);

  transporter.verify(function(error, success) {
        if (error) {
                console.log(error);
        } else {
                console.log('server is ready to send emails');
          }
        })
  transporter.sendMail(mailOptions, function(error, info) {
        if (error) {
              console.log(error);
              return callback(err, null);
        } else {
              console.log('Message sent: ' + info.response);
              return callback(null, info);
          }
        })
    }
Run Code Online (Sandbox Code Playgroud)

Har*_*lis 6

您可以使用此链接允许计算机远程访问您的 gmail ,但请记住,Google 会影响您的默认帐户(即使您已连接到另一个帐户)。

The easy way: use a incognito / private window (to have no google account connected) and log in your google account and then use the link above.

If that doesn't work try updating your nodemailer to the latest version.