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

ε祈祈猫儿з 提交于 2020-06-27 18:33:26

问题


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'** 

回答1:


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

Go to Mail Settings

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

    });


来源:https://stackoverflow.com/questions/60094539/not-able-to-send-emails-from-nodemailer-with-office365-account-in-nodejs-getting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!