Emails
The following table is an overview of the Email delivery by environment.
| Development | Staging | Production | |
|---|---|---|---|
| Handlebars | x | ||
| SendGrid | x | x |
Handlebars Service
The psuedo-name for the service that sends our emails in development is referred to as Handlebars (after the template compiler). The two main benefits for going with this approach are:
Isolation of email templates between different enviornment. A common request is to add copy changes to existing emails. Depending on the request, some additional work might be needed, in which case we don't want to ruin what is already deployed on production.
An escape hatch to mitigate damages done to our Email reputation. Previously, we would use sendgrid to deliver test emails. This hindered our email deliverys and caused our marketing emails to end up in some customer's spam box. See Configuring New Emails for steps on how to create new emails for each environment.
There's an open source SendGrid Library called Bamboo that we to help build and deliver our emails.
Bamboo allows for a configurable Adapter, which allows us to switch out delivery methods per environment. We configure which adapter to use in Peacemaker.Credentials.determine_sandbox_environment/0.
Both of the adapters that live in email_adapters.ex assume that the node service is running on port 9414. All of this work is handled by Peacemaker.HandlebarsService. This is a GenServer that uses the Port module to run /_internal/handlebars/wrapper.sh on port 9414. This is then monitored by a Supervisor that is configured in application.ex. We do not need to run this service in production, because we call out to Bamboo SendGridAdapter, which uses the resources referenced by SendGrid instead of email_templates.
Configuring New Emails
The general flow looks something akin to:
Create the template in SendGrid
Copy the Template-ID and create a new
<template-id>.htmlfile under theemail_templatesdirectory in the root of the Peacemaker application with the new code.We currently use Peacemaker.Email to configure our email templates.
When ready, copy code contents from
/email_templatesover to SendGrid.
NOTE: Peacemaker's Dockerfile has a line that copys all files in /email_templates and bundles it with the peacemaker application. This is how we're able to support staging deployments.