Nov 20, 2023
In a previous blog post, we discussed how Amazon SES is the most affordable way to send reliable emails (with some tradeoffs to consider). In this blog post, we'll share an example on how to create email templates within Amazon SES.
Creating an Amazon SES template
Unfortunately, templates can't be created from the Amazon SES dashboard, so we'll use code to setup the template.
To do this, we'll use the npm library for Amazon SES. Install with:
In the code example below, we're creating an HTML template in the
htmlBody variable and then passing that to Amazon SES.
Note the dynamic variable
name in the template body. Amazon SES allows for Handlebars templating within the template for variables, conditionals, partials, and more. We'll pass in the dynamic data while sending the email on the next step.
Sending emails through an SES template
When we're ready to send an email, we'll use
SendEmailCommand to pass data to our template. The data is just the variables that our template is expecting in order to populate the template. In this simple example, it's just the
Assuming everything was configured properly, after running the code, our email should be sent with the template data populated.
Tip: you can monitor delivery of these emails by connecting Amazon SES to Amazon SNS – learn more.
A note on HTML email templates
For simple HTML emails with minimal formatting, writing raw HTML for templates works just fine.
However, when it comes to advanced formatting (eg. layouts, buttons, branding), the code for these templates quickly becomes a mess to maintain. This is primarily due to the challenges of cross-client support which forces developers to write 90s style HTML with inline CSS paired with tables within tables within tables. For details on cross-client support, caniemail.com is a wonderful resource.
To help remedy this, developers often use email template frameworks like MJML. These frameworks abstract many of these pain points into a highly reusable component based system that works across clients out of the box.
Looking for a more collaborative approach?
While component libraries are a step in the right direction, product teams often find that this approach can still lead to significant developer bottlenecks since template code is still within their codebase. This means every time a template needs to be adjusted or marketing wants to test different copy, a developer is needed for changes, pull requests, deploys, etc.
This is why some collaborative teams opt for a new approach – using an email API with a built-in template builder like Waypoint. Waypoint in particular has a powerful template builder geared for data-rich emails paired with an easy to use API.
Screenshot of Waypoint’s powerful transactional email template builder
The added benefit of Waypoint is much better observability as well.
Screenshot of Waypoint’s logs on a single email.
Let's face it, Amazon SES is hard to beat on price. But as we discussed in a previous blog post, SES is like buying wholesale and has it's limitations. For teams that want to collaborate around product emails, it's worth considering alternative approach with a visual template builder.