NodeMailer NPM is used for sending emails through node server. You can send the HTML content also using it. It is a module that makes easy to sending emails through NodeJs.
![Nodemailer In Nodejs](http://www.fluttertpoint.in/wp-content/uploads/2024/03/FlutterTPoint-Card-5-1024x576.png)
The NodeMailer can be downloaded or installed using npm:
: npm install nodemailer
After downloading the module you can add it or require the module like this.
var nodemailer = require('nodemailer');
Send an email
Now you can send an email like this by providing the required parameters.
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'your-email-password'
}
});
var mailOptions = {
from: '[email protected]',
to: '[email protected], [email protected]',
subject: 'Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
Send HTML
You can also send the HTML content in the body of the mail.
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Email using Node.js',
html: '<h1>Welcome</h1><p>This is the body!</p>'
}
Thank you for reaching out us. You can see more about it from here.
See also:
Adding JWT Authentication in NodeJs Application
How to use Websocket in NodeJs