Send Email from Node.js

Node.js is an open-source, cross-platform runtime environment for developing server-side Web applications. Although Node.js is not a JavaScript framework, many of its basic modules are written in JavaScript, and developers can write new modules in JavaScript. The runtime environment interprets JavaScript using Google's V8 JavaScript engine.

First you need to install nodemailer package in your application. Use following command to install this package.
$ npm install nodemailer
Now add following code in your application to send email. Make sure to update all required values in below code to send email successfully.
var nodemailer = require('nodemailer');

var mailTransport = nodemailer.createTransport('smtps://');

var mailOptions = {
   from: "Sender Name <>",
   to: "Recipient Name <>",
   subject: "Hello World",
   text: "Test email with node.js"
   html: '<b>Test email with node.js</b>'

mailTransport.sendMail(mailOptions, function(error, info){
        return console.log(error);
    console.log('Message sent: ' + info.response);
If you are still facing any issue with sending email through Gmail stmp servers make sure you are using correct login details. For 2 factor authentication enabled account required to generate application specific password and set here. Also you allow less secure apps in your Gmail account.

About Author:

I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Newer Post
Older Post


Post a Comment