Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Send Emails Using Nodemailer in Nodejs?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 97
    Comment on it

    For sending emails using Nodejs we will be using The Nodemailer module.

    Nodemailer is a module that provides sending emails from the NodeJs application.

     

    Here are some features of the Nodemailer module:

     

    1) Zero Dependencies.

    2) Support email with attachments.

    3) Support multiple services i.e Gmail, AOL, Hotmail, Yahoo, Godaddy etc.

    4) Security.

     

    Installation :

    npm install nodemailer save

     

    Sample Code:

    var  nodemailer = require('nodemailer');
    //Using Gmail smtp transport
    var transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
            user: 'gmail.user@gmail.com',
            pass: 'yourpass'
        }
    });
    // setup email data with unicode symbols
    var mailOptions = {
        from: '"Ankit Chettri" <ankit.chettri@gmail.com>', // sender address
        to: 'test_example@evontech.com, test_example@evontech.com', // list of receivers
        subject: 'Hello', // Subject line
        text: 'Hello world', // plain text body
        html: '<b>Hello world </b>' // html body OR html file path as per requirement
    };
    // Code to send mail
    transporter.sendMail(mailOptions, function(error, response) {
        if (error) {
            console.log(error);
        } else {
            console.log("Message sent: " + response.message);
        }
        transporter.close();
    });

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: