2022 年 5 月 30 日之后的 Nodemailer 和 Gmail

UJ *_*dia 25 javascript email gmail node.js nodemailer

在此输入图像描述

使用 NodeMailer 和 Gmail 发送电子邮件

Google 报告称,5 月 30 日之后第三方应用程序将无法使用用户名和密码登录。这是否会影响 NodeMailer。我们通常在 gsuit gmail 设置中允许不太安全的应用程序,然后再在 Nodemailer 中使用它。

    var transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
         user: 'youremail@address.com',
         pass: 'yourpassword'
        }
     });
Run Code Online (Sandbox Code Playgroud)

小智 43

如果您生成一个应用程序密码来使用 nodemailer,将会有所帮助。

  1. 首先,您需要开启双因素身份验证。
  2. 然后在您的管理帐户中转到安全性
  3. 您可以在两步验证下方看到应用密码。
  4. 转到应用程序密码,选择应用程序其他并写入自定义应用程序名称(示例项目名称),然后单击生成。
  5. 您将获得一个密码,使用该密码而不是您的邮件密码。

  • 对于无法通过第 3 步的用户,链接为:[https://myaccount.google.com/apppasswords](https://myaccount.google.com/apppasswords) (5认同)