ItSolutionStuff.com

How to Send Email using Gmail Account in Node.js?

By Hardik Savani • August 24, 2021
Node JS

Hello,

This post will give you example of node js send email example. I’m going to show you about node js send email through gmail. this example will help you node.js send email with nodemailer. you can understand a concept of how to send a mail using node js.

In this example we will use nodemailer npm package for sending email. here we will use sender as google gmail account and you have to add your email and password in sender details.

so let's follow simple step to send mail with node js.

Step 1: Create Node App

run bellow command and create node app.

mkdir my-app

cd my-app

npm init

Step 2: Install nodemailer

run bellow command and install nodemailer npm package.

npm install nodemailer -S

Step 3: Create server.js file

server.js

const nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({

service: 'gmail',

auth: {

user: "your_gmail_account@gmail.com",

pass: "PASSWORD"

}

});

let message = {

from: "from@email.com",

to: "receiver_email@gmail.com",

subject: "Subject",

html: "<h1>Hello SMTP Email</h1>"

}

transporter.sendMail(message, function(err, info) {

if (err) {

console.log(err);

} else {

console.log(info);

}

})

now you can simply run by following command:

node server.js

Output:

i hope it can help you...

Tags: Node JS
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

šŸ“ŗ Subscribe on YouTube

We Are Recommending You

ā˜…

How to Get Client IP Address in Node JS?

Read Now →
ā˜…

How to Render HTML File in Node JS Express?

Read Now →
ā˜…

How to Create Separate Routes File in Node JS Express?

Read Now →
ā˜…

How to Get Query String Value in Node.js?

Read Now →
ā˜…

Node JS Express Route with Parameters Example

Read Now →
ā˜…

How to Create Route in Node JS Express JS?

Read Now →
ā˜…

How to Generate 4,6,8,10 Digit Random number in Node JS?

Read Now →
ā˜…

Node JS Read and Write Json File Example

Read Now →
ā˜…

Node JS Find and Update Object in Array Example

Read Now →
ā˜…

Node JS Make HTTP Delete Request Example

Read Now →
ā˜…

Node JS Express Form Submission Example

Read Now →
ā˜…

Node JS Convert Image File to Base64 String Example

Read Now →