Node JS - Node js send an email - Node - Node JS tutorial - webnode
How to Send an Email in Node.js ?
- Now you are ready to send emails from your server.
- Use the username and password from your selected email provider to send an email.

The Node mailer Module:
- The Nodemailer module can be downloaded and installed using npm:
C:\Users\Your Namenpm install nodemailer
- After you have downloaded the Nodemailer module, you can include the module in any application:
var nodemailer = require('nodemailer');
Example
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'yourpassword'
}
});
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sending Email using Node.js',
text: 'Wikitechy is an enhanced tutorials'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
- And that's it! Now your server is able to send emails.
Related nodejs article tags - node js - node js tutorial - node js examples
Multiple Receivers:
- To send an email to more than one receiver, add them to the "to" property of the mailOptions object, separated by a comma:
Example:
- Send email to more than one address:
var mailOptions = {
from: '[email protected]',
to: '[email protected]o.com, [email protected]',
subject: 'Sending Email using Node.js',
text: 'Wikitechy is an enhanced tutorials'
}
Send HTML:
- To send HTML formatted text in your email, use the "html" property instead of the "text" property:
Example:
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sending Email using Node.js',
html: '<h1>Welcome to wikitechy</h1><p>Wikitechy is an enhanced tutorials</p>'
}