Exporting a Dyspatch Template to AWS SES

Build beautiful emails quickly with Dyspatch and send them to your customers using Amazon's Simple Email Service.

Downloading Your Email Template

Once your email has been reviewed and approved by your team's stakeholder, you can now export your template using the Download Template button.

You will need to select the HTML/Handlebars option to be compatible with SES's templating system.

Selecting the download button and exporting to handlebars for SES

A zipped file will be downloaded onto your system with the HTML, plain text content, metadata, and localizations (if applicable).

Putting the Template in SES

SES templates are created through the AWS API. We recommend setting up an API integration with Dyspatch so your templates can always be in sync.

You can also use AWS's API directly to create templates. The script below assumes you have jq installed and the AWS CLI tool correctly set up.

First, save the below script as "upload.sh"

#!/usr/bin/env sh
DIR="/tmp/template"

# Extract the template to /tmp/template
unzip "$1" -d $DIR

# Set up variables
file="`ls $DIR/*.html`"
html_file="${file##*/}"
template_name="${html_file%%.*}"
metadata_file="$template_name-metadata.txt"

# Escape Name
ses_template_name="`echo $template_name | sed -Ee 's/[[:blank:]]+/_/g'`"

# Test for optional txt file
if test -f "$DIR/$template_name.txt"; then
    txt_file="$template_name.txt"
    txt_content="`cat $DIR/$txt_file`"
else
    txt_content=""
fi

# Get subject line
subject="`cat \"$DIR/$metadata_file\" | grep 'Subject:' | awk '{sub($1 FS, ""); print}'`"

# Get template content
html_content="`cat \"$DIR/$html_file\"`"

# Construct the JSON object
jq --null-input\
   --arg html "$html_content"\
   --arg txt "$txt_content"\
   --arg subject "$subject"\
   --arg name "$ses_template_name"\
   '{"Template": {"TemplateName": $name, "SubjectPart": $subject, "HtmlPart": $html, "TextPart": $txt}}'\
   > $DIR/template.json

# Upload to AWS
aws ses create-template --cli-input-json file://$DIR/template.json

echo "Uploaded template: '$template_name'"

Then, make the script executable

$ chmod +x upload.sh

Now you can upload the Dyspatch template in the zip file you downloaded. Make sure to replace [Dyspatch Template Name] with the actual file name!

$ ./upload.sh "[Dyspatch Template Name].zip"

Verify that the template was uploaded by going to SES > Email Templates.

Showing SES

You're done! Your template is now ready to send through SES.

Didn't find what you're looking for?

Ask our support team, we're here to help!

Contact Support