Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to send emails from nodemailer with office365 account in nodejs getting error Authentication unsuccessful?

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'** 
like image 958
Salesforce Developer Avatar asked Oct 15 '22 06:10

Salesforce Developer


1 Answers

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: '[email protected]', // 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'});
    }

    });
like image 51
Vamsi Ambati Avatar answered Nov 15 '22 13:11

Vamsi Ambati