How can I find out why my Amazon SES email using the SendTemplatedEmail operation fails to get delivered?

Last updated: 2019-04-03

I'm using the SendTemplatedEmail operation to send messages from my Amazon Simple Email Service (Amazon SES) account. However, some emails are never delivered. How can I find out what failed?

Resolution

When you use an email template, Amazon SES validates that the template data you send includes the variables that are required in the template. If the template data has invalid or missing variables, then Amazon SES can't deliver the email. This is called a Rendering Failure.

To find out why an email wasn't delivered using the SendTemplatedEmail operation, set up Rendering Failure event notifications using Amazon Simple Notification Service (Amazon SNS).

After you set up Rendering Failure event notifications, you'll receive an Amazon SNS notification when a templated email delivery fails. The notification includes information about what part of the template data led to the Rendering Failure.

For example, this template contains the variables name and favoritecolor:

{
  "Template": {
    "TemplateName": "ExampleTemplate",
    "SubjectPart": "Hello, {{name}}!",
    "HtmlPart": "<h1>Hello {{name}},</h1><p>Your favorite color is {{favoritecolor}}.</p>",
    "TextPart": "Dear {{name}},\r\nYour favorite color is {{favoritecolor}}."
  }
}

If you send the following template data, Amazon SES won't deliver the email, because favoritenumber isn't a valid variable in the template:

"TemplateData": "{ \"name\":\"Jane\", \"favoritenumber\": \"10\" }"

With Rendering Failure event notifications, you'll receive a failure notification similar to the following:

{
    "eventType": "Rendering Failure",
    "mail": {
        "timestamp": "2019-09-09T04:38:19.788Z",
        "source": "sender@example.com",
        "sourceArn": "arn:aws:ses:us-west-2:1234567890123:identity/sender@example.com",
        "sendingAccountId": "1234567890123",
        "messageId": "01010161a734a0eb-a706827a-3bda-490f-8eaa-63cf4b00d10c-000000",
        "destination": [
            "receiver@example.com"
        ],
        "headersTruncated": false,
        "tags": {
            "ses:configuration-set": [
                "RenderFailure"
            ]
        }
    },
    "failure": {
        "errorMessage": "Attribute 'favoritenumber' is not present in the rendering data.",
        "templateName": "ExampleTemplate"
    }
}

Follow these guidelines to avoid Rendering Failures:

  • Check the capitalization of variable names in your template data. Variable names in the template are case sensitive.
  • Verify that your template data has the all the variables in the template.

Did this article help you?

Anything we could improve?


Need more help?