首页 > 解决方案 > Nodemailer:在 prod 中发送电子邮件不起作用,但在本地工作中发送它们

问题描述

我正在使用 gmail 和 nodemailer 在我的 nodejs 应用程序中发送电子邮件。
我正在使用这个选项:
在此处输入图像描述

启用使用该 gmail 帐户发送密码。

奇怪的是,这在本地工作得很好,但在 prod 中它不起作用,我得到这个错误:

~ 文件:emailServices.js ~ 第 68 行 ~ 错误错误:无效登录:534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv

534-5.7.14 C_k04HIybV5ampaq-t350mMioC50ryqetyrL6tihifwJHVt_1-5ahsYJ8JYb0IT34QSqZ

534-5.7.14 DkukvbTnIdTmckxb3ykL5Vf1pVL2L5NwGcL_fe1yRKIiikKWbmwLQT2AEWEkjALw>

534-5.7.14 请通过网络浏览器登录,然后重试。

534-5.7.14 了解更多信息

534 5.7.14 https://support.google.com/mail/answer/78754 cf11sm38885edb.65 - gsmtp

这是它的配置方式:

var transport = nodemailer.createTransport({
  service: "gmail",
  auth: {
    user: process.env.SUPPORT_EMAIL,
    pass: process.env.SUPPORT_EMAIL_PASSWORD,
  },
});

onst sendEmailAsync = async function sendEmailAsync(
  destination_email,
  subject,
  html_email_content
) {
  const mailOptions = {
    // I think here it is why the email received is lodeepstartup
    from: "email@gmail.com",
    to: destination_email,
    subject: subject,
    html: html_email_content,
  };

  return new Promise((resolve, reject) => {
    transport.sendMail(mailOptions, function (error, info) {
      if (error) {
        reject(false);
      } else {
        resolve(true);
      }
    });
  });
};

注意:
在 prod 中部署应用程序后,我收到来自谷歌的警报,说有人登录,但我点击按钮验证是我。
那么,也许谷歌一直将我的 VPS 列入黑名单,使其无法使用该电子邮件登录?

标签: emailgmailvpsnodemailerproduction

解决方案


推荐阅读