Nodemailer 与 Gmail |出现错误:错误:无效登录:535-5.7.8 用户名和密码不被接受

2024-01-07

我正在尝试使用带有 Gmail 帐户的 Nodemailer 在我的应用程序中设置电子邮件验证。

我的问题是它报告错误,指出我的用户名和密码尚未被接受:

There was an error: Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials a3sm2007362wri.89 - gsmtp
const transporter = nodemailer.createTransport({
  host: "smtp.gmail.com",
  service: "Gmail",
  port: 465,
  secure: true,
  auth: {
    user: process.env.USER,
    pass: process.env.PASS,
  },
});

transporter.sendMail(
  {
    from: process.env.USER,
    to: email,
    subject: subject,
    text: text,
  },
  (error) => {
    if (error) {
      return console.log("There was an error: " + error);
    }
    console.log("Email sent successfully");
  }
);

我可以确认process.env.USER and process.env.PASS是正确的,而且我也允许不太安全的应用程序.

有什么我遗漏/不理解的吗?


“从 2022 年 5 月 30 日起,Google 不再支持使用要求您仅使用用户名和密码登录 Google 帐户的第三方应用或设备。”https://support.google.com/accounts/answer/6010255?hl=en https://support.google.com/accounts/answer/6010255?hl=en

Solution

  1. 转到您的 Google 帐户
  2. 查找安全菜单
  3. 启用两步验证
  4. 之后您将在安全页面中看到“应用程序密码”选项。 (如果没有在 Google 帐户搜索框中搜索。
  5. 从“选择应用程序”下拉列表中选择邮件
  6. 从“设备”下拉列表中选择设备,然后单击“生成”按钮。
  7. 复制密码并在需要时在您的应用程序中使用它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Nodemailer 与 Gmail |出现错误:错误:无效登录:535-5.7.8 用户名和密码不被接受 的相关文章

随机推荐