Node.js dummy email queue, when SMTP fails.

There are many npm packages that solves the following issue.

                           |--------|
/--X--| SMTP 1 |
/ ^ |--------|
/ \--- Retry with next provider
|----------------|/ |--------| |------------------|
| Mail | ---X--> | SMTP 2 | /->| ^_^ Happy user |
|----------------|\ ^ |--------| / |------------------|
\ \--- Retry /
\ |--------| /
\---->| SMTP 3 |--/
|--------|

The following diagram is taken from Meteor-Mailer which is based on nodemailer which im going to use in the example below.

Code below is responsible for the following
1. Try to send email with default email (here it would be Meteor.JS email system)
2. If it fails, it starts email queue
3. It tries to send email with first email provider. If this fails it tries again with another.
4. If all fails, error callback is called.

Not that this script is dummy, in real scenarios real queue should be used, for instance one that is saved in Mongo.


Node.js dummy email queue, when SMTP fails. was originally published in Qunabu Interactive on Medium, where people are continuing the conversation by highlighting and responding to this story.