Use multiple email providers, or fall back to disk backups, when using nodemailer. NS avoids providers with high latency intelligently and can also redirect all email to console or disk when testing and debugging.
Nodemailer Strategies will let you customize your own email strategies, to give you better control if one email providers goes down, or you run your code in test.
With the in-built strategy blocks you can build a strategy that will switch between Gmail and SendGrid, and if both go down, it will fall back to disk. and print the emails to console or you can build a completely different one with suits you better.
When you are testing your application, just replace your production stragy with a Console strategy or a fallback strategy, and you wont have to touch the rest of your email code.
var nodemailer = require"nodemailer";var ns = require"nodemailer-strategies";var googleTransport = nodemailercreateTransport"SMTP"service: "Gmail"auth:user: "email@example.com"pass: "userpass";var sendGridTransport = nodemailercreateTransport"SMTP"service: "SendGrid"auth:user: "apiUser"pass: "apiKey";var emailStrategy =name: "lower-latency" options:name: "nodemailer" options: googleTransportname: "nodemailer" options: sendGridTransportname: "fallback" options: path: "./queuedEmails/"var mailOptions =from: "Fred Foo ✔ <firstname.lastname@example.org>" // sender addressto: "email@example.com, firstname.lastname@example.org" // list of receiverssubject: "Hello ✔" // Subject linetext: "Hello world ✔" // plaintext bodyhtml: "<b>Hello world ✔</b>" // html bodyemailStrategysendMailmailOptionsconsole.log"Executed the strategy with success? %s" success
name:"delay" options:path: "path to storage directory"
Will use x number of other stragies (usually nodemailer strategies) and use statistics to select the best performing one, and switch favorites if performance degrades.
name:"lower-latency" options:providers: strategy blocks
This strategy will always "fail" and thus proceede to the next strategy in the line.
name:"delay" options:time: 1000
name: "nodemailer" options: nodemailerTransport
This library was built to ensure that long running node processes can automatically send emails even though one or several of the email providers become offline. Nodemailer Strategies will try email providers in the order the user has determined. It can also use a latency aware wrapper around several email providers to ensure that the most responsive provider is used, and that unstable providers are quickly ignored.
This design was chosen after SendGrid was victim of a DDoS attack and it became apparent that many webapplications have resilient architecture when it comes to application servers, databases and networking equipment, but not e-mail providers.
All contributions are welcome. To get your provider accepted, you need to supply tests and notify the maintainers of any needed credentials to test your provider.