Nodemailer

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.

The current version of Nodemailer v3+ is licensed under EUPL-v1.1 license. Commercial license availbale. See license details in the License page or buy here.

In addition to twaking Nodemailer I can provide support for almost any email related issues (IMAP, SMTP, RFC822), see details in the support page.

If you do not want to upgrade from the MIT licensed Nodemailer 2 then you can see the old docs here, otherwise see the light migration guide here.

npm install nodemailer --save

Nodemailer features

  • A single module with zero dependencies – code is easily auditable, as there are no dark corners
  • Heavy focus on security, no-one likes RCE vulnerabilities
  • Unicode support to use any characters, including emoji 💪
  • Windows support – you can install it with npm on Windows just like any other module, there are no compiled dependencies. Use it hassle free from Azure or from your Windows box
  • Use HTML content, as well as plain text alternative
  • Add Attachments to messages
  • Embedded image attachments for HTML content – your design does not get blocked
  • Secure email delivery using TLS/STARTTLS
  • Different transport methods in addition to the built-in SMTP support
  • Sign messages with DKIM
  • Custom Plugin support for manipulating messages
  • Sane OAuth2 authentication
  • Proxies for SMTP connections
  • ES6 code – no more unintentional memory leaks, due to hoisted var’s

Requirements

  • Node.js v6+. That’s it.

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.

TL;DR

In short, what you need to do to send messages, would be the following:

  1. Create a Nodemailer transporter using either SMTP or some other transport mechanism
  2. Set up message options (who sends what to whom)
  3. Deliver the message object using the sendMail() method of your previously created transporter
Example

This is a complete example to send an email with plain text and HTML body

'use strict';
const nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: [email protected]',
        pass: 'yourpass'
    }
});

// setup email data with unicode symbols
let mailOptions = {
    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
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
        return console.log(error);
    }
    console.log('Message %s sent: %s', info.messageId, info.response);
});

Using Gmail might or might not work out of the box. See instructions for setting up Gmail SMTP here.

Source code

  • Nodemailer source code is available on Github
  • MailParser source code is available on Github
  • smtp-server source code is available on Github
  • mailsplit source code is available on Github

Examples

  • Nodemailer AMQP example is an example of using RabbitMQ to manage Nodemailer email messages. Source.

Nodemailer is created by Andris Reinman. The Nodemailer logo was designed by Sven Kristjansen.