Here, we will write a code to send e-mail using node js. For this we will require the necessary libraries and use node mailer to performe the function
app.js file
var nodeMailer=require('nodemailer');
var transport=nodeMailer.createTransport({
host:'smtp.gmail.com',//Simple Mail Transfer Protocol (SMTP)? SMTP is used to send and receive email
port:587,
secure:false,
requireTLS:true,//TLS is a way to provide secure connections between a client and a server.
auth:
{
user:'yourEmail@gmail.com',
pass:'app password' //google how to create app password for your gmail
}
});
var mailOptions = {
from: 'yourEmail@gmail.com',
to: 'yourEmail@gmail.com',
subject: 'node mail',
text: "hello node"
}
transport.sendMail(mailOptions,function(error,info)
{
if(error)
{
console.warn(error);
}
else{
console.warn('email has been send',info.response);
}
})