Node.js Sending Email Nodemailer Tutorial

Node.js Sending Email Nodemailer Tutorial

Today, We want to share with you Node.js Sending Email Nodemailer Tutorial.
In this post we will show you Sending Email Using Node.js example, hear for Sending an email using NodeMailer & Gmail we will give you demo and example for implement.
In this post, we will learn about How To Send Email In Node.js Tutorial with an example.

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

Read Also:  Angular 9/8 Material Input Box Examples

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.

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);
routersemail.post('/', sEmailhandleSHello); // nodejs handle the route at Pakainfo.com/welCome

function sEmailhandleSHello(req, res) {
    //and display Not the movie in transporter!
    var stransportermail = sendnodemailermail.createTransport({
        service: 'pakainfo',
        auth: {
            user: '[email protected]', // write Your email id required
            pass: '**[email protected]#$' //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 Pakainfo.com).

Read Also:  Check if Checkbox Checked Unchecked using Angular Example

 

var data_text_mail = 'Welcome to Pakainfo.com \n\n' + req.body.name;

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

 
var SemailmailOptionsdata = {
    from: '<[email protected]>', // write your Email sender address
    to: '[email protected]', // 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 Pakainfo.com ✔</b>' // 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.

Read Also:  jQuery Capture Webcam Image Using Web Camera in PHP

 

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

We hope you get an idea about Node.js Sending Email Nodemailer Tutorial
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.

votes
Article Rating

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments