Node.js nodemailer模块成功消息,但从未收到电子邮件

时间:2019-10-17 15:31:56

标签: javascript node.js gmail nodemailer

我之前已经实现了nodemailer,但从未遇到过如此奇怪的问题。主要是信息说邮件已发送,但我从未收到。 例如,当我向我的邮件终结点发出API请求时,这是服务器的输出:

{ from: 'mail@gmail.com',
  to: 'my-personal-mail@gmail.com',
  subject: 'Your xx password',
  html:
   '<p>Hi, Name <br>, We received a request to reset your password. <br> Therefore your new password is: <stong>yiH5S0P43M</strong></p>' }
{ accepted: [ 'to-my-personal-mail@gmail.com' ],
  rejected: [],
  envelopeTime: 396,
  messageTime: 689,
  messageSize: 448,
  response: '250 2.0.0 OK  1571325863 25sm1485661lje.58 - gsmtp',
  envelope:
   { from: 'mail@gmail.com',
     to: [ 'my-personal-mail@gmail.com' ] },
  messageId: '<message-id-here@gmail.com>' }

因此,从回调信息消息来看,基本上一切似乎都很好,错误消息也为null,但消息未通过。这里按照我的实际代码实现

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: "gmail",
  auth: {
    user: 'mymail@gmail.com',
    pass: 'mypassword'
  }
});

const mailOptions = {
from: 'mymail@gmail.com', // sender address
to: `${docs[0].email}`, // list of receivers
subject: 'Your password', // Subject line
html: `<p>Hi, ${docs[0].first_name} <br>, We received a request to reset your password. <br> Therefore your new password is: <stong>${new_password}</strong></p>`
};
 transporter.sendMail(mailOptions, function(err, info) {
 console.log(err, info)
 if (err)
 return res.status(500).send();
 else
 return res.status(200).send({
 status: 'OK',
 message: 'Success.',
  });
});

顺便说一句,我已经在gmail上启用了Less Secure Apps,这不是我第一次实现nodemailer,但这是我第一次遇到此问题...

0 个答案:

没有答案