Node.js Send an Email

Node.js Send an Email

Node.js nodemailer module is used to send an Email.

The Nodemailer module can be downloaded and installed using npm as below command.

D:\nodejs\website> npm install nodemailer

You can include above downloaded package in your application as below.

var nodemailer = require('nodemailer');

You can send email using host,port and aunthentication details like username, password as below.

Example :

 

var nodemailer = require('nodemailer');

        var transporter = nodemailer.createTransport({

                host: "smtp-relay.*********.com",

                port: 8888,

                auth: {

                        user: '******@gmail.com',

                        pass: '***********'

                }

        });

 

        var mailOptions = {

                from: 'arya*******@gmail.com',

                to: 'rec*****@yahoo.com',

                subject: 'Send an email using Node Js!',

                html: 'Welcome to aryatechno tutorials!!!'

        };

 

        transporter.sendMail(mailOptions, function (error, info) {

                if (error) {

                        console.log("error:" + error);

                        return false;

                } else {

                        console.log('Email sent: ' + info.response);

                        return true;

                }

        });

 

Comments

Leave a Reply

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

20323