DEV Community

Cover image for Email sending in Node.js
Steve Lebleu
Steve Lebleu

Posted on • Updated on

Email sending in Node.js

As a developer, email sending is a recurent task across the projects.

Most part of time, you have to deal with open source libraries, to switch from a library to another accross the projects, with some particular implementations and / or behaviors.

As well, you can have a different need inside a same project just regarding the use case.

For example, you can still need to send an email to a developer when a particular event is fired, or send a transactionnal email to say welcome to a new user.

In the first case, a simple SMTP server can do the job internally.

In the second case, it's more efficient to rely to a web API, able to manage statistics, bouncing, DKIM, templating, ...

As well, you can need to deal with different providers at the same time. During a migration, for example.

Some months ago, I was wondering how to provide something flexible and consistent to deal with this kind of repetitive issue.

And I did it myself, because it was quite fun. 😎

All the cases described above - and some others - are covered by a light NPM package.

The main features are:

  • Configuration based
  • Agnostic appoach: same input, same output for all configurations
  • Formalized transactions conventions
  • Unlimited number of transporters inside the same project
  • Support of different sending modes (SMTP and web API)
  • Embeded view engine, stream or web API templates

There is Cliam, an agnostic and very flexible tool to deal with transactional email sending.

GitHub logo steve-lebleu / cliam

Agnostic transactional email sending in Node.js environment

Cliam

Github action workflow status Coverage Status CodeFactor GitHub Release GPL Licence

Transactional emails with a kick

Agnostic transactional email sending in Node.js environment πŸ’₯ πŸ’ͺ πŸ’Š

> Why ?

To improve and facilitate the implementation, flexibility and maintenance of transactional emailing tasks.

> Features

  • Agnostic transactional email sending using web API or SMTP server. One input, one output.
  • Multiple simultaneous transporters.
  • Configuration based, not implementation based : easy switch between different modes.
  • Normalized transactions events.
  • Securized payloads.
  • Customisable default templates.

> Table of contents

> Requirements

  • Node.js >= 18.19.0
  • NPM >= 10.2.3

> Getting started

Install

> npm i cliam --save
Enter fullscreen mode Exit fullscreen mode

Configure

Create a .cliamrc.js module on the root of your project.

> touch .cliamrc.js
Enter fullscreen mode Exit fullscreen mode

Define a minimalist configuration in .cliamrc.js newly created:

require('dotenv').config();
module.exports = {
  "sandbox": true,
  "transporters": [
    {
      "id"
…
Enter fullscreen mode Exit fullscreen mode

Currently, following web api providers are supported: Mailgun, Mailjet, Brevo, Sendinblue, Sendgrid, Mandrill, Sparkpost, Mailsender and Postmark. Amazon SES and a lot of others should be integrated soon, but I prefer take the focus on some new features and to push more robustness before to embedd too much transporters.

Have a good dev, enjoy and feel free to use and to share πŸš€

Top comments (0)