Member-only story

Create email templates with EJS and send them with Mailgun

Tom Nagle
2 min readAug 8, 2018

--

In this article we will create a HTML generator using EJS and send the HTML email with mailgun -js.

What we’re going to do:

  1. Create a function to generate HTML given some parameters and an EJS template
  2. Create a mailgun-js configuration file
  3. Create a function to send an email given the required inputs
  4. Create a trigger that brings it all together
  5. Test everything along the way

Assumptions:

  • You have a mailgun account setup and configured correctly
  • You have a existing Node application that supports EJ6
  • You have Jest installed and configured

First, install some dependencies by running yarn add ejs-promise mailgun-js winston

Create the HTML template generator. The generator will take a name of a template and the parameters that the template will use. It assumes that your template is in a /templates` folder.

We need to test the HTML generator to make sure it outputs what we are expecting and protect against regression. It’s important that we test the…

--

--

Tom Nagle
Tom Nagle

Written by Tom Nagle

I am a full stack JavaScript developer, living in Melbourne, Australia. My preferred stack is Mongoose, TypeScript, Node.js, React & GraphQL.

No responses yet