/nodejs-nodemailer-gmail

A guide to using Node.js, Nodemailer, and Gmail effectively

Primary LanguageTypeScript

NodeJS, Nodemailer + GMAIL

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

Get your App Password (Gmail)

  1. Go to Google Account Manage accounts and enable 2 Factor Authentication https://myaccount.google.com/security
  2. Go to the Google Account you want to use for sending email through NodeMailer.
  3. Visit https://myaccount.google.com/apppasswords.
  4. Give your app a name like "NodeMailer", then click Create.
  5. Copy the App password generated by Google.

Setup .env file

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

Contact Me

For any questions, mail me on efenstakes101@gmail.com.

Good Luck and happy coding.