AWS

How to:- Managing Email Templates in AWS SES

In this article I will explain how to manage email templates in AWS SES. Let’s understand what is the email templates. Templates include a subject line and the text and HTML parts of the email body. In the templates, subject and body sections contain unique values. It can be personalized for each recipient.

Use the Amazon SES API to update, delete, view the contents of the existing templates.

You may also like:

Managing Email Templates in AWS SES

These are the command to manage email templates in AWS SES.

View List of Email Templates

We can use the ListTemplates operation in the Amazon SES API to view list of all of our existing email templates.

Follow this below command to view a list of email templates:

# aws ses list-templates

Otput:

{
"TemplatesMetadata": [
{
"Name": "SpecialOffers",
"CreatedTimestamp": "2020-08-05T16:04:12.640Z"
},
{
"Name": "NewsAndUpdates",
"CreatedTimestamp": "2019-10-03T20:03:34.574Z"
}
]
}

If there are no any templates created you will get a TemplateMetadata object with no members as an output.

View the content of an email template

We can use the GetTemplate operation using Amazon SES API to view the contents of a email template.

Follow the below command to view the email template contents:

# aws ses get-template --template-name MyTemplate

Command output example:

{
"Template": {
"TemplateName": "TestMessage",
"SubjectPart": "Amazon SES Test Message",
"TextPart": "Hello! This is the text part of the message.",
"HtmlPart": "\n\n
"Hello! This is the HTML part of the message.
}
}

Replace MyTemplate with the name of the template that you want to view. If the template name that you provide doesn’t match it will returns a TemplateDoesNotExist error.

Delete an email template

Using DeleteTemplete operation with Amazon SES API we can delete a specific email template.

Use this below command to delete email template:

# aws ses delete-template --template-name MyTemplate

Replace MyTemplate with the name of the template that you want to delete. The above command will not provide any output you have to verify it using GetTemplate operation.

Update an email template

We can use UpdateTemplate operation with Amazon SES API to update an existing email template. This operation will help if you want to change the subject line of the email template or if you want to modify the body of the message itself.

First, use the GetTemplate command to retrieve the exiting template by using this below command:

# aws ses get-template --template-name MyTemplate

Replace MyTemplate with the name of the template that you want to retrieve.  If it matches with existing template this command will returns a response that resembles the below example:

{
"Template": {
"TemplateName": "TestMessage",
"SubjectPart": "Amazon SES Test Message",
"TextPart": "Hello! This is the text part of the message.",
"HtmlPart": "\n\n
" Hello! This is the HTML part of the message."
}
}

Second, create a new file and paste the output of the above command into the file.

Third, as per your requirements changes the template and save the file as update_template.json.

Now run the below command to update the email template:

# aws ses update-template --cli-input-json file://path/to/update_template.json

Replace file://path/to/update_template.json with your update_template.json file which you created in previous steps.

After template updated above command will not return any output. You can verify your changes using GetTemplate operation.

If mentioned template doesn’t exist the command will return TemplateDoesNotExist error.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment