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.