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

42,924

Solution 1

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

Solution 2

Go to Less secure app access . convert icon Allow less secure apps to ON.

Link : https://myaccount.google.com/lesssecureapps

Share:
42,924
Haider Yaqoob
Author by

Haider Yaqoob

Updated on July 28, 2022

Comments

  • Haider Yaqoob
    Haider Yaqoob almost 2 years

    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);
      }
    });
    
  • Tanishq Vyas
    Tanishq Vyas almost 3 years
    what if it does not work even after doing the same for a node.js backend ?
  • Zedd
    Zedd almost 3 years
    This didn't work for me even though I've switched the Allow less secure apps: ON