News

Nodemailer v2.3

Proxies

This update adds built-in support for major proxy protocols. Instead of providing your own custom getSocket handler to generate a socket through SOCKS or HTTP protocol, provide a proxy configuration url and that’s it.

var smtpConfig = {
    host: 'smtp.gmail.com',
    port: 465,
    ...,
    // proxy config
    // assumes a HTTP proxy running on port 3128
    proxy: 'http://localhost:3128/'
};

You can find details about proxy support here.

Dynamic transport loading

To ease custom trasport loading, there is now a new configuration option called transport. This way you would not have to load the transport plugin in your code (you do need to install the transport plugin before you can use it), you only need to modify the configuration data accordingly.

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
    transport: 'ses', // loads nodemailer-ses-transport
    accessKeyId: 'AWSACCESSKEY',
    secretAccessKey: 'AWS/Secret/key'
});

Nodemailer v2.2

The newest Nodemailer v2.2.0 release brings several new features including:

Support for proxies

Nodemailer does not have support for actual proxy protocols, so you can’t just define “use socks5” or something like that. Instead it provides a way to use external sockets that can be initiated by some 3rd party proxy module, for example by socks. You can see an example for using SOCKS5 with Nodemailer here

iCalendar support

There’s a new message option icalEvent that can be used to define calendar events for messages. The value is an object that takes two properties: method (defines the calendar method, eg. “REQUEST”) and content which contains the actual iCalendar data.

var message = {
    ...,
    icalEvent: {
        method: 'request',
        // content can be a string, a buffer or a stream
        // alternatively you could use `path` that points to a file or an url
        content: 'BEGIN:VCALENDAR\r\nPRODID:-//ACME/DesktopCalendar//EN\r\n...'
    }
}

List headers

Instead of adding List-* headers manually there’s now special message property for it: list. It takes a structured object and turns it into required List-* headers

var message = {
    ...,
    list: {
        // List-Help: <mailto:[email protected]?subject=help>
        help: '[email protected]?subject=help',
        // List-Unsubscribe: <http://example.com> (Comment)
        unsubscribe: {
            url: 'http://example.com',
            comment: 'Comment'
        },
        // List-Subscribe: <mailto:[email protected]?subject=subscribe>
        // List-Subscribe: <http://example.com> (Subscribe)
        subscribe: [
            '[email protected]?subject=subscribe',
            {
                url: 'http://example.com',
                comment: 'Subscribe'
            }
        ],
        ...
    }
};

Sending eml files as messages

If you have already generated a raw mime message and want to sent it instead of letting Nodemailer to generate the message structure, then you can use message property raw to define it. In this case you also need to set the SMTP envelope as mime message is not parsed for the sender and recipients info.

var message = {
    raw: 'Content-Type: text/plain\r\nSubject: Test\r\n\r\nHello world!',
    // envelope needs to be set as raw is not processed
    envelope: {
        from: '[email protected]',
        to: '[email protected]'
    }
}

Or load from a file:

var message = {
    raw: {path: '/path/to/message.eml'},
    envelope: {
        from: '[email protected]',
        to: '[email protected]'
    }
}

Additionally it is possible to use pregenerated content for message nodes as well. In this case the message is generated normally, except for these specific attachments that use predefined content.

var message = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'test message',
    text: 'Hello world!',
    attachments: [
        {
            raw: 'Content-type: text/plain;\r\n\r\nNode contents
        }
    ]
}

Using raw for attachments or any other content overrides any headers that would be normally added

Configuration validator

If you use SMTP transport (either normal or pooled) then you can use verify method to check if your configuration actually works or not. This method tries to create a connection to the SMTP server and authenticate itself but it does not send any mail.

// verify connection configuration
transporter.verify(function(error, success) {
   if (error) {
        console.log(error);
   } else {
        console.log('Server is ready to take our messages');
   }
});

Under the hood updates

In addition to new features there’s some updates under the hood as well. For example Nodemailer does not use Quoted-Printable encoding for every string content anymore. When mostly using non-latin alphabets, then Quoted-Printable encoding makes no sense at all. Instead, Nodemailer switches to base64 encoding for such content. If you want to define the used content transfer encoding yourself, you can set it with the textEncoding option.

Another notable change is in direct transport where it always tries to upgrade the connection from plaintext to ciphertext with STARTTLS. If upgrade fails, then client continues in plaintext mode. This should fix the “broken red lock” icon in Gmail for the messages sent using Nodemailer direct transport.

Nodemailer v2.1.0

This release packs some stability improvements (notably related to custom headers) and new features.

Most important new feature is templating support. You can now create a template based sending function by providing a template or an external template renderer and that’s it, you can start sending by providing only the template context to this function. Read more about the template support here.

The other new feature is support for 'idle' events and isIdle() method to be able to manage large queues more effectively. Here’s an example for using RabbitMQ based queues when sending mail.

Nodemailer v2.1.0-rc.0

Nodemailer v2.1.0-rc.0 is the first rc release for the v2.1.0 version. Stable is released 7 days after the last rc version, so for now the stable is planned for january 27th.

Install it with:

npm install nodemailer@beta

Notable changes are related to better custom headers support and templating. Templating can be used with built-in simple rendering or by providing a node-email-templates renderer, see the docs for examples.

Update

The relase of v2.1.0-rc.1 moved stable release date to february 1st.

Nodemailer v2.0 released

Nodemailer v2.0 is now officially released.

Install it with:

npm install nodemailer --save

Changes compared to previous versions

  • SMTP support is now completely bundled (including direct and pool based sending) into Nodemailer and no additional plugins are required to use these. You can even use connection urls like these for easier configuration management:
    • var conf = "smtps://user:[email protected]?pool=true"
    • var conf = "direct:?name=myhostname.com"
  • All dependencies are completely locked, so no ^ or ~ version selectors anymore. This should ensure that in case there’s something wrong with Nodemailer you can safely downgrade to a previous version that you know that should work.
  • Logging got an overhaul. Instead of emitting ‘log’ events, Nodemailer takes a logger option which could be a bunyan compatible logger instance (Nodemailer uses debug, info and error calls)
  • Stream errors are not silently swallowed anymore. If you set an HTTP URL as an attachment and Nodemailer fails to fetch this URL, then sending is aborted and the resulting error is returned with the callback. Previous behavior was to ignore the error and append the error message to the attachment content
  • Full emoji support ?! Any string values, including attachment file names can include emojis ?
  • format=flowed is not used anymore when generating plaintext mime parts. This still caused issues with some clients even though the standard is from the nineties
  • Not visible to users but Nodemailer now uses ESLint instead of jshint to weed out any code issues