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
There are just List of 5 steps to sending an email using nodejs with angularjs
1 : First of all Install the nodemailer 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 nodemailer 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: '**!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 Pakainfo.com).
var data_text_mail = 'Welcome to Pakainfo.com \n\n' + req.body.name;
STEP 4: Create a simple JSON object with the necessary values for sending the email.
var SemailmailOptionsdata = { from: '', // 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: 'Welcome to Pakainfo.com ✔' // 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){ 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!.