'535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully

I'm trying to send email via nodemailer. And sender email is of microsoft azure. But I'm getting error-response: '535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. MFA is enabled. Also I have generated app password. Can anyone please help me with this issue. Code snippet to send mail-


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);


Solution 1:[1]

I can see in your code that you are using secure: false field.
Instead of secure: false field you can change into secureConnection: false.

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

Make sure to check in your package.json file the "nodemailer" : "*" dependency is added, if not make sure to add it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SuryasriKamini-MT