Menu Close

How to Send HTML Email using Node.js?


NodeJs is an open-source run-time environment that organizes everything you would like to execute a program written in JavaScript. It’s used for running scripts on the server to render content before it’s delivered to an internet browser.

NPM stands for Node Package Manager, which is an application and repository for developing and sharing JavaScript code.

Follow the below steps to send the email.

The Nodemailer module makes it easy to send emails from your computer.

Install Nodemailer using npm install

C:\users\codeamend>npm install nodemailer 

After you have install the Nodemailer module, you can include the module in any application.


Once you are installed the nodemailer package you are ready to send emails from your server.

Use the username and password from your selected email provider to send an email.

To send HTML formatted text in your email, use the “html” property instead of the “text” property:

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: '',
    pass: 'yourpassword'

var mailOptions = {
  from: '',
  to: '',
  subject: 'Test Email using Node.js',
  html: '<h1>codeamend</h1><p>That was easy!</p>'

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
  } else {
    console.log('Email sent: ' + info.response);

Also read “How to Send an Email using Node.js?” –

View More Details about the nodemailer package –

How useful was this post?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 12

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?


Posted in NodeJs, NPM

Leave a Reply

Your email address will not be published. Required fields are marked *

You can also read...