This is a guide on how to use NodeJS, Nodemailer and Gmail.
For Gmail to be used with nodemailer, we have to use App Passwords
now because they changed the old style of using email
and password
.
In this repo, I create a simple nodejs function that can send emails.
To start using this repo, clone it from github:
git clone https://github.com/efenstakes/nodejs-nodemailer-gmail
- Go to Google Account Manage accounts and enable
2 Factor Authentication
https://myaccount.google.com/security - Go to the Google Account you want to use for sending email through NodeMailer.
- Visit https://myaccount.google.com/apppasswords.
- Give your app a name like "
NodeMailer
", then clickCreate
. - Copy the App password generated by Google.
In .env
, add a GOOGLE_MAIL_APP_PASSWORD
variable key and set the value as the App Password
you copied from Gmail.
You're ready to rock. Just run:
npm run start
For any questions, mail me on efenstakes101@gmail.com
.
Good Luck and happy coding.