Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

node.js - 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'** 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...