8

With the shut down of Less secure apps by Google on May 30, 2022, using Gmail with nodemailer now throws an error that says 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. The Nodemailer docs appears to not be updated yet regarding this issue of Less secure apps but suggest to use another delivery provider. I used to just turn on LSA, store the credentials in an environment variable and let nodemailer do its thing, with this change, how can one still use gmail with nodemailer? There are no youtube tutorials to fix this yet and looking at the google documentation, it doesn't show nodemailer

Nugget
  • 81
  • 1
  • 6
  • 23

3 Answers3

26

Solved it by creating App password inside Google account. You must have 2-step verification actived.

2-step actived

App password created

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Gustavo Pinto
  • 466
  • 4
  • 7
3
  1. Open Mail > Settings > See all Settings > Forwarding and POP/IMAP.
  2. Enable POP download: & Enable IMAP access: (then save the settings). Mail Settings Image
  3. Open Your Gmail Account > security > 2-step verification(enable it).
  4. Go to App Passwords > select device > select app(you can create any custom app).
  5. Copy App Password and use it in your application.
2

You should look into xoauth Nodemailer appears to support serval oauth options

let transporter = nodemailer.createTransport({
  host: "smtp.gmail.com",
  port: 465,
  secure: true,
  auth: {
    type: "OAuth2",
    user: "user@example.com",
    clientId: "000000000000-xxx0.apps.googleusercontent.com",
    clientSecret: "XxxxxXXxX0xxxxxxxx0XXxX0",
    refreshToken: "1/XXxXxsss-xxxXXXXXxXxx0XXXxxXXx0x00xxx",
    accessToken: "ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x",
    expires: 1484314697598,
  },
});
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 1
    I used OAuth2 to solve the issue I followed this tutorial https://dev.to/chandrapantachhetri/sending-emails-securely-using-node-js-nodemailer-smtp-gmail-and-oauth2-g3a – zribi yacine Jun 08 '22 at 20:54
  • Xoauth2 is the more secure option really. There is no telling how long apps password will continue to work. Im happy you got it working – Linda Lawton - DaImTo Jun 09 '22 at 06:32