Member-only story
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:
- Create a function to generate HTML given some parameters and an EJS template
- Create a mailgun-js configuration file
- Create a function to send an email given the required inputs
- Create a trigger that brings it all together
- 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…