Nodemailer is a module for Node.js applications to allow easy as cake email sending. The project got started back in 2010 when there was no sane option to send email messages, today it is the solution most Node.js users turn to by default.
Nodemailer is licensed under MIT license. See license details in the License page. If you are upgrading from Nodemailer v2 or older, then see the light migration guide here.
npm install nodemailer
If you really like Nodemailer or your business benefits from it financially then I would really appreciate a small donation. You can either use Bitcoin or PayPal for donations.
15Z8ADxhssKUiwP3jbbqJwA21744KMCfTM
.Try out the all new ultimate email debugging app by Nodemailer.
You can park all your domains for your future projects at Project Pending free of charge. You get name servers and DNS management, a single HTTPS landing page (or redirect) and an email account.
Project Pending is a service from the makers of Nodemailer.
If you are able to run Node.js version 6 or newer, then you can use Nodemailer. There are no platform or resource specific requirements. All public Nodemailer methods support both callbacks and Promises (if callback is omitted). You need to have at least Node v8.0.0 if you want to use async..await with Nodemailer.
In short, what you need to do to send messages, would be the following:
This is a complete example to send an email with plain text and HTML body
"use strict";
const nodemailer = require("nodemailer");
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
let testAccount = await nodemailer.createTestAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass, // generated ethereal password
},
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Fred Foo 👻" <[email protected]>', // sender address
to: "[email protected], [email protected]", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});
console.log("Message sent: %s", info.messageId);
// Message sent: <[email protected]>
// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);
Output of the the example script as shown by the Ethereal mail catching service:
Nodemailer source can be found from Github.
Nodemailer is created by Andris Reinman. The Nodemailer logo was designed by Sven Kristjansen.