'nodejs -nodemailer cannot send email after allowing less secure apps access

This is my first time using nodejs with nodemailer to send an email from a dummy account I have .When trying to send an email I got the error

"  code: 'EAUTH',
  response: '535-5.7.8 Username and Password not accepted. Learn more at\n' +
    '535 5.7.8  https://support.google.com/mail/?p=BadCredentials w17sm3259346ejk.112 - gsmtp',
  responseCode: 535,
  command: 'AUTH PLAIN'"

My credentials are correct and I have enabled access from less secure apps to my gmail account.I also tried removing @gmail.com from my user but I still get the same error .

My code :

const mailer = require('nodemailer');

const  transporter = mailer.createTransport({
  service: 'gmail',
  port:587,
  auth: {
    user: '[email protected]',
    pass: 'my pass '
  }
});

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



function sendEmail(){

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

module.exports = {sendEmail}; 

I would appreciate your help here . Please don't mark this as a duplicate as I have already searched here .



Solution 1:[1]

Receiver's mail also should enabled less secure apps. otherwise your mail not reach the destination.

Solution 2:[2]

You also need to temporary allow access to your account in order to sign in on your new application or device.

Use: Display Unlock Captcha

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SL codegen
Solution 2 Abjiuru Seth