Send email using Node Mailer in Node.JS
Send an Email using Node-Mailer Through Gmail in Node.JS.
2 min readJun 21, 2020
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.
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.
- go to link https://myaccount.google.com
- in the Left side Menu click Security Option.
- Click on App Password.
- After Entering the Password you will see the following screen.
- 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 👐 🙌