Node.js dummy email queue, when SMTP fails.

Mateusz Wojczal
Jan 24, 2019 · 1 min read

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.

Escolasoft

Stories from web&mobile software house based in Poland

Mateusz Wojczal

Written by

founder of Qunabu Interactive from Gdańsk, Poland. Full-stack web developer with over a dozen years of experience.

Escolasoft

Stories from creative software house based in Poland, with a love for all web technology

Mateusz Wojczal

Written by

founder of Qunabu Interactive from Gdańsk, Poland. Full-stack web developer with over a dozen years of experience.

Escolasoft

Stories from creative software house based in Poland, with a love for all web technology

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store