Home » Node.js

How to send emails with Nodemailer using HTML as content | Node.js

Sending emails using Nodemailer: Here, we are going to learn how to send emails with attachments using Nodemailer using HTML as content in Node.js?
Submitted by Godwill Tetah, on September 15, 2019


  1. How to send emails using Nodemailer | Node.js
  2. How to send emails with attachments using Nodemailer | Node.js

This time around, we will see how to compose or build/format our email body using HTML?


// load the node mailer module
var nodemailer = require('nodemailer');    

//configure the transporter

var transporter = nodemailer.createTransport({    
  service: 'gmail',
  auth: {
    user: '[email protected]',
    pass: 'your gmail password'

//email  options

var mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Sending Email using Node.js',
  html: '<h1> Node JS </h1> <br> <h5> Hello World</h5>'

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

Note: You can use the same format and send as many attachments as possible. Make sure the closing curly bracket of each attachment is separated by a comma sign (,).

Finally, start your node app and if sending is successful, the phrase ‘email sent' will be printed out on the console or terminal.

Check you're the email's inbox.

Using Gmail as your transporter, you can also enable the less secure app access setting.

Nodemailer 1

Sending email requires internet connection.

Do not fear about your password security. It's a tested and secured module used by many since 2010.

Nodemailer 2

Nodemailer 3

Thanks for coding with me! See you @ the next article. Feel free to drop a comment or question.

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.