Saturday 25 February 2017

Email Sending Using Node.js

Send email using nodejs,Angularjs and express in 5 simple steps

First of all I am going to more discuss Nodejs about sending (gmail,yahoo,etc.)e-mail with Node.js.
and then i am going to more use Angularjs.js and NodeMailer(Nodejs) package.

LIST OF FEATURES : Sending Email Using Node.js

1 : It works with SSL(secure)server and TLS(insecure) smtp servers
2 : in nodejs, supports new smtp authentication(auth.) (PLAIN,CRAMMD5,LOGIN.etc)
3 : in nodejs,all emails are queued (list )and the queue is sent (emails) asynchronously format
4 : in nodejs, supports sending Simple or more functionality html emails and basic emails templates with multiple(one or more) attachments (MIME)
5 : send mail with attachments(pdf,doc,txt,images.etc..) can be added as also strings,and other streams or url file paths send
6 : The header supports to the utf-8 headers pass data and body mail in nodejs

There are just List of 5 steps to sending an email using nodejs with angularjs

1 : First of all Install the node­mailer package.
2 : Create a transport object using nodemailer.createTransport() and pass it your email credentials.
3 : Prepare the message to be sent in the body(nodejs).
4 : info (cridentials)Create an object with (HOST,PORT,EMAIL,USERNAME,PASSWORD)information about the sender, email subject(Like ), recipient and the body content that we prepared earlier.
5 : Send the email using — transporter.sendMail() in nodejs

STEP 1: Step-by-step Install the node­mailer package in nodejs.

1 npm install nodemailer

STEP 2: Second step creating a transport the object in your application route handler in nodejs apps.

var sendnodemailermail = require('nodemailer');
var routersemail = express.Router();
app.use('/welCome', routersemail);'/', sEmailhandleSHello); // nodejs handle the route at
function sEmailhandleSHello(req, res) {
    //and display Not the movie in transporter!
    var stransportermail = sendnodemailermail.createTransport({
        service: 'ng4free',
        auth: {
            user: '', // write Your email id required
            pass: '**!password@#$' //Setup Your password required
    ...//your content
    ...//your content
    ...//your content

STEP 3: Now Third step Prepare some content plaintext mail or HTML content send mail to be sent in the HTML body.
Now In this script,I am going to simply(plain mail) use some text(Like welcome to

1 var data_text_mail = 'Welcome to \n\n' +;

STEP 4: Cre­ate a sim­ple JSON object with the nec­es­sary val­ues for send­ing the email.

var SemailmailOptionsdata = {
    from: '<>', // write your Email sender address
    to: '', // write your Email list of receivers
    subject: 'My First Nodejs Email send', // write your Email Subject line
    text: data_text_mail //, // plaintext body
    // html: '<b>Welcome to
<img draggable="false" class="emoji" alt="✔" src="
// You can choose to send an HTML body instead

STEP 5: Good luck. Actually send sucessfully the email using nodejs and handle display the response in nodejs.

transporter.sendMail(SemailmailOptionsdata, function(mail_error, resultdata){
        res.json({info: 'mail_error'});
        console.log('Message sent: ' + resultdata.response);
        res.json({info: resultdata.response});