Send Mail in Node Js

node js
mail
npm module

Node mailer used to send emails to the user, this node mailer available in node modules.

npm install nodemailer --save

In short, what you need to do to send messages, would be the following:

  • Create a Nodemailer transporter using either SMTP or some other transport mechanism
  • Set up message options (who sends what to whom)
  • Deliver the message object using the sendMail() method of your previously created transporter

This is a complete example to send an email with plain text and HTML body

'use strict';
const nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'gmail.user@gmail.com',
        pass: 'yourpass'
    }
});

// setup email data with unicode symbols
let mailOptions = {
    from: '"Abc Xyz" <abc@xyz.com>', // sender address
    to: 'def@ghi.com, klm@nop.com', // list of receivers
    subject: 'Hello Subject', // Subject line
    text: 'Hello world Body?', // plain text body
    html: '<b>Hello world ?</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
        return console.log(error);
    }
    console.log('Message %s sent: %s', info.messageId, info.response);
});

 

 

You might also like:

File Upload Using Angular Js and Node Js

28-05-2018 AngularJs Node js file upload multer module

How to upload file by using request module

18-03-2017 request module node js

How to change background color and color to the text using javascript

27-02-2017 css javascript colors

How to get drop down value when drop down change using javascript

27-02-2017 onchange events dropdown javascript functions

How to set or update or push the values into Object in javacript

27-02-2017 javascript set update push object