# Exporting a Dyspatch Email to AWS SES


<!--alex ignore simple-->
Build beautiful emails quickly with Dyspatch and send them to your customers
using Amazon's Simple Email Service.

# Downloading Your Email Email
Once your email has been reviewed and [approved by your team's
stakeholder](/emails/submitting_an_email/#draft-approved), you can now
export your email using the **Export** button.

You will need to click the **Download Icon** in the Amazon SES option to be compatible with
SES's templating system.

![Download modal with arrows pointing to download email option for SES](https://docs.dyspatch.io/img/exports/download-ses-email.png)

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

### Putting the Email in SES

SES emails are created through the [AWS
API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html#send-personalized-email-create-template).
We recommend setting up an <a href="https://docs.dyspatch.io/api/" target="_blank">API integration</a>
with Dyspatch so your emails can always be in sync.

You can also use AWS's API directly to create emails. The script below
assumes you have <a href="https://stedolan.github.io/jq/" target="_blank">jq</a> installed and the <a href="https://aws.amazon.com/cli/" target="_blank">AWS
CLI tool</a> correctly set up.

First, save the below script as "upload.sh"
```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

```sh
$ chmod +x upload.sh
```

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

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

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

<img class="img-border" src="https://docs.dyspatch.io/img/exports/ses-list.png" alt="Showing SES email templates list" />

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