Templated transactional emails in MJML

Remove boilerplate SMTP code, take advantage of templates in any language, and fix email client issues with MJML.

The Status Quo

As a developer, having worked on many applications I think I’ve written a “forgotten your password” email a thousand times. The same goes for “Welcome to product X” or “Purchase confirmation”.

These transactional emails are a simple necessity in almost all apps and thankfully they’re not that complex. You just have to write some HTML. And it’s dynamic, so setup a template language, like Twig, Handlebars, or Jinja2.

For good measure, add a plain-text version for old email clients and spam filters.

Now send it, just integrate a library like SwiftMailer, or Nodemailer, configure your SMTP or API details within your framework of choice.

Oh, but this email needs a PDF attachment, and of course that’s dynamically generated too, and you probably need to see quite a few versions of the email and PDF before you’re done, so maybe build a way to test what they look like in development.

Speaking of development, you’re not actually sending these email are you? No, you’re probably using Mailhog, or Mailcatcher.

Reinventing the wheel

So it’s simple. No really, most of us developers have done this many times and not had much trouble. But it’s a lot of work. All this time spent configuring libraries, tools and services, when there’s so many more interesting things to build.

All of these libraries and tools have improved this considerably, but in the new era of microservices and 12factor apps, I think we can do better.

Enveloper is a simple API-driven service which you can run through a public docker image, mount your templates, configure credentials for your favourite mail delivery service, and you’re ready.

Now a simple API request will:

  • Parse and resolve placeholders using a template language like Twig
  • Convert MJML to HTML (optional, but a massive time-saver, and fixes a load of rendering issues)
  • Send your message through your provider

Additionally, it:

  • Handles plain text versions
  • Supports multiple attachments
  • Is capable of many (and mixed) template languages and preprocessors

Head over to Github to get started, or to Twitter to follow along for updates on new features; there’s plenty on the way! Have an idea or a question? Missing something? I’m happy to help.




PHP developer. http://t.co/olQvZ91Lo4

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Real-Time mode — index administration

Vector in Rust

KintoHub your Kubernetes

Experience In Masai :

Achilles heel of agility

Ride the waterfall agile

Ultimate List of WordPress Statistics (Updated 2022)

Ordeals of a small exporter in India. Part 2

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
Adam Quaile

Adam Quaile

PHP developer. http://t.co/olQvZ91Lo4

More from Medium

A Beginner’s Guide to - SAML Authentication

Running dcm4chee on MacOS


Sonar Setup with SAP Commerce