I get a error "{ Error: Invalid login: 535-5.7.8 Username and Password not accepted." when I try send a mail with the module nodemailer from Node JS

I ran into this recently and it was related to the Less secure apps settings on the account.

Choosing "Allow users to manage their access to less secure apps" fixed it.

enter image description here


Turn on Allow less secure apps at https://www.google.com/settings/security/lesssecureapps


I'd the same problem earlier but after removing '@gmail.com' from username worked fine for me.
Error '535-5.7.8 Username and Password not accepted' occurs only in following mentioned cases:

  1. Wrong credentials.
  2. adding @gmail.com in the username, avoid it!
  3. two-factor authentication enabled. If yes, then disable it.
  4. https://myaccount.google.com/lesssecureapps if it is OFF, turn it ON to enable lesssecureapps.