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.
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);
routersemail.post('/', sEmailhandleSHello); // nodejs handle the route at ng4free.com/welCome
function sEmailhandleSHello(req, res) {
//and display Not the movie in transporter!
var stransportermail = sendnodemailermail.createTransport({
service: 'ng4free',
auth: {
user: 'admin@ng4free.com', // 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 techieupgrader.in).
1 var data_text_mail = 'Welcome to ng4free.com \n\n' + req.body.name;
STEP 4: Create a simple JSON object with the necessary values for sending the email.
var SemailmailOptionsdata = {
from: '<admin@youremail.com>', // write your Email sender address
to: 'php@youremail.com', // 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 techieupgrader.in
</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.
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});
};
});