7

I am using nodemailer to send emails to user with office 365 account email and password are all correct but every time i am getting error - Authentication unsuccessful

Error: Invalid login:Authentication unsuccessful[BL0PR01CA0033.prod.exchangelabs.com]
code: 'EAUTH',
response: '535 5.7.3 Authentication unsuccessful [BL0PR01CA0033.prod.exchangelabs.com]',
response Code: 535,
command: 'AUTH LOGIN'** 
biruk1230
  • 3,042
  • 4
  • 16
  • 29

4 Answers4

5

You have to enable SMTP login for the O365 mail box or user in the admin settings

Go to Mail Settings

Go to Mail Settings

Turn On Authenticated SMTP

Turn On Authenticated SMTP

once that is done use

var transport = nodemailer.createTransport({
    service: "Outlook365",
    auth: {
      user: 'O365email',
      pass: 'O365password'
    }, 

  });
  var mailOptions = {
   from: 'o365email',
    to: 'exaple@gmail.com', // list of receivers
    subject: "Password reset requested for your account", // Subject line
    text: 'reset password',
    html: "<h1>Mail Testing</h1>" // html body
  };
  transport.sendMail(mailOptions, function(error, response){
    if(error){
      resp.status(500);
     resp.send(error);
    }else{
        resp.send({message:'done'});
    }

    });
Vamsi Ambati
  • 321
  • 1
  • 4
  • 9
0

I have faced the same problem and after a lot of research and following few document. I came to this solution that As an Office365 (now Microsoft365) customer I need to go to portal.azure.com, then "Manage", "Properties" and set "Manage Security defaults" to "no". I think this is messed up, but it works.

https://learn.microsoft.com/en-us/azure/active-directory/fundamentals/concept-fundamentals-security-defaults

https://github.com/nodemailer/nodemailer/issues/1071

Here is the setting what I am using

host: "domain.com",
port: 587,
secure: false,
auth: {
  user: "email@domain.com",
  pass: "password"
},
tls:  { ciphers: 'SSLv3' },
service: "Outlook365",
Zahra
  • 2,231
  • 3
  • 21
  • 41
0

The easy way to fix this is here: https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission#use-the-microsoft-365-admin-center-to-enable-or-disable-smtp-auth-on-specific-mailboxes

Under the title: Use the Microsoft 365 admin center to enable or disable SMTP AUTH on specific mailboxes

You need to enable SMTP AUTH for the email you are adding creds for.

Simone Anthony
  • 524
  • 6
  • 15
0

In my case, I logged on to my outlook email account and changed the POP settings to let devices and apps use POP, I also verified my account.

Everything worked well afterward.

Bassey Rhema
  • 174
  • 1
  • 5