Send email using Node Mailer in Node.JS

Send an Email using Node-Mailer Through Gmail in Node.JS.

TUSHAR KANJARIYA
2 min readJun 21, 2020
Send email using Node Mailer in Node.JS

Hello Developers,
in our real life, we are using a mailer system to get notified of our users for new updates.

Today we will learn how to send an email using node.JS using node mailer package.

So, Let’s Get Started

  • Initialize Project
$ mkdir mail-system
$ cd mail-system
$ npm init

In npm init fill all the info asked by the npm and open in your favorite code editor.

  • install Dependencies.
$ npm install nodemailer
  • create mailer.js file and write the following code.
sending mail in node.JS using nodemailer

Let’s Run Our Code.

  • Open your terminal/command prompt and run command node mailer.js and see the Output.
  • And also check the Receiver G-mail Inbox to receive mail.

Note:

If you are using your Gmail Account with two-factor authentication then first you will follow these steps Otherwise you can skip this Note Section.

Two Factor Authentication
  • After Entering the Password you will see the following screen.
Select Other (Custom name)
  • And Enter the name ‘nodemailer’ and click Generate Button.
  • It will show a popup of your generated password.
  • Copy that password and paste it into your code Like this.
var transportar = Mailer.createTransport({
service: "gmail",
auth: {
user: "youremail@example.com",
pass: "Paste_Your_Password_Here", // Paste Password Here
},
});

Let’s Run our code to Test it.

Feel Free to ask for help.

Let me know if you have any queries in the comment section.
Thanks 👐 🙌

--

--

TUSHAR KANJARIYA

Working as a Full Stack Developer in @Simform and UI/UX Designer By Hobby