Nodemailer is a module for Node.js applications to send email using Gmail or any email providing service like Mailgun etc. But to use Gmail you may need to configure "Allow Less Secure Apps" in your Gmail account ( configure gmail account ) unless you never able to send email. So, it's better to send mail using Mail Services like MailGun where a sandbox is created to receive mail.
To configure it with Gmail, you need to specify host i.e smtp.gmail.com.
transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 447, // Gmail Port
auth: {
user: account.user, // Gmail id
pass: account.pass // Gmail password
}
});
var mailOptions = {
from: // sender address
to: // list of receivers
subject: // Subject line
text: // plaintext body
html: // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
Sendmail function will send mail based on mail options. If you are using some email service then you need to change transporter object.
Thanks
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Rajat khurana
Rajat is a bright Javascript Developer, he has good knowledge of HTML, WordPress, NodeJs, Core Java, Javascript, Jquery. Apart from this he loves to play Badminton and PC Gaming.