Error: Invalid login: 535-5.7.8 Username and Password not accepted

Haider Yaqoob picture Haider Yaqoob · Dec 5, 2019 · Viewed 25.7k times · Source

The code below is perfect to send emails using node.js code/program. However, still getting error mentioned in the title.

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: '[email protected]',
    pass: '**********'
  }
});

var mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

Answer

Haider Yaqoob picture Haider Yaqoob · Dec 5, 2019

Yes, code is perfect. However, you need to allow less secure apps from your google account to send emails. Through this link. Allow less secure apps From your Google Account