NodeMailer Username PAssword Not Accepted Solution
NodeMailer Username PAssword Not Accepted Solution

Nodejs, nodemailer is not working, returning log error saying: Invalid login: 535-5.7.8 Username and Password w\node_modules\nodemailer\lib\smtp-connection\index.js:1536:34)    not accepted..

response: '535-5.7.8 Username and Password not accepted.

Solution – Why nodemailer is not sending email

-> If your google account is enabled with 2-factor authentication, then you can’t use your regular password as authentication while creating transport auth to access & send email programmatically.

var transporter = nodemailer.createTransport({
    service:'gmail',
    auth:{
        user:'rajatrrpalankar@gmail.com',
        pass:'your regular password'   // instead you should use app specific password here
    }
}); // initialize create Transport service

To send email using nodejs nodemailer you need to generate app-specific login credential(password) & use it as auth password.

How to generate app-specific password for gmail access

To send email from your nodejs script using nodemailer you need to generate app-specific password, using which you can get accessed to your gmail account to send email from nodejs app.

Follow the steps

Login to Google Account, Goto MyAccount (Manage your google Account) -> Security -> App Password

How to generate app password in google account

Select App Passwords,

Select app -> a drop down will appear -> select choose custom name

Give a app custom name as: nodemailer and click on GENERATE button

As you can see above, password for nodemailer auth is created. copy this password & paste it in nodejs script

var transporter = nodemailer.createTransport({
    service:'gmail',
    auth:{
        user:'rajatrrpalankar@gmail.com',
        pass:'paste google app password here'
    }
}); // initialize create Transport service

and BOOM, you can now easily send email using nodejs mailer.

Complete Nodejs Script to Send Email using nodemailer