Nodemailer with Gmail and Nodejs

How do I send email from nodemailer in nodejs using gmail?

less secure apps is deprecated util 14/06/2022

you need to enable two step auth in your google account
https://myaccount.google.com/signinoptions/two-step-verification?rapt=AEjHL4Nm5j8lzlmlfGjIPZ3JQPadURur-daRW6csSgARqTeML2jsYhw3cctrxLoOZXEWpIivj6eXEcaFt_EfQct4VY40OwxOEg

and create App Password
https://myaccount.google.com/apppasswords?rapt=AEjHL4PZB2jtGe1EVQ1dS_jyte5bhU_hn44yc3rDR0k3BnmcIqzmocSf5sBDIN88P8vB7-owMYAWLK6m37OyA-_2C6IE7qapTg

so google will send a App password that you can login with nodemailer

How to send emails with google using nodemailer after Google disabled less sure app option?

At the time of writing, Less Secure Apps is no longer supported by google. And you can't use your google account password.

You're gonna have to generate a new app password.

App passwords only work if 2-step verification is turned on.
Follow this steps to get the app password

  1. Go to https://myaccount.google.com/security
  2. Enable 2FA
  3. Create App Password for Email
  4. Copy that password (16 characters) into the pass parameter in Nodemailer auth.
const client = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "username@gmail.com",
pass: "Google-App-Password-Without-Spaces"
}
});

client.sendMail(
{
from: "sender",
to: "recipient",
subject: "Sending it from Heroku",
text: "Hey, I'm being sent from the cloud"
}
)

Nodemailer and Gmail after May 30 2022

It would help if you generated an app password to use nodemailer.

  1. First, you need to turn on two-factor-authentication.
  2. And then in your manage account go to security.
  3. You can see the app password below two-step verification.
  4. Go to app password select app other and write custom app name (example project name) and click on generate.
  5. You get a password use that password instead of your mail password.

How to use Nodemailer with Google?

When you want to send email over Gmail SMTP, google enable you to set up App password. You have to have set up 2-Step verification in your google account. Once 16 digit password are generated, you just replace password for login (username is your email address, that does not change).

Sources:

Google: Sign in with App Passwords

Nodemailer authorization error with gmail

After you turn of two-factor authorization, you also need to turn of the settings in your google account to allow less-secure apps. You can do it from https://myaccount.google.com/lesssecureapps

Then, it will give you a randomly generated password to use with Nodemailer. Your actual password doesn't work.



Related Topics



Leave a reply



Submit