535 5.7.139 认证失败,请求不满足认证成功的条件

Mus*_*sal 8 azure node.js nodemailer

我正在尝试通过nodemailer 发送电子邮件。发件人电子邮件是 microsoft azure。但我收到错误响应:'535 5.7.139 身份验证失败,请求不符合成功身份验证的标准。请联系您的管理员。MFA 已启用。我还生成了应用程序密码。谁能帮我解决这个问题。发送邮件的代码片段-


var userTransporter = nodemailer.createTransport({
  host: 'smtp.office365.com',
  port: 587,     // secure SMTP
  secure: false,
  auth: {
    user:SENDER_EMAIL,
    pass: SENDER_APP_PASSWORD,
  }
});

    var mailOptions = {
        from: SENDER_EMAIL,
        to: email,
        template: path.join(__dirname, "../public/views/email-verification"),
        context: {
          token: otp,
          email: email,
          url: EMAIL_VERIFICATION_LINK,
          name: user_name
        },
      };
      let mail = await transporter.sendMail(mailOptions);
Run Code Online (Sandbox Code Playgroud)

小智 0

我可以在您的代码中看到您正在使用secure: false字段。
您可以将secure: false字段更改为secureConnection: false ,而不是 secure: false 字段

var userTransporter = nodemailer.createTransport({
  host: 'smtp.office365.com',
  port: 587,     // secure SMTP
  secureConnection: false,
  auth: {
    user:SENDER_EMAIL,
    pass: SENDER_APP_PASSWORD,
  }
});

Run Code Online (Sandbox Code Playgroud)

确保检查您的package.json 文件中是否添加了“nodemailer”:“*” 依赖项,如果没有,请确保添加它。