Why are emails failing to deliver when I send Amazon SES emails using the SendTemplatedEmail operation?

Last updated: 2021-03-25

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 contains non-compliant variables or is 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 error message includes information about the template variable that 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 can't deliver the email, because the favoritecolor variable from the template is missing.

Important: Including extra variables that aren't present in the template, like favoritenumber, won't cause an error. However, all variables included in the template must have an exact case-sensitive counterpart in the template data.

"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 'favoritecolor' 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 includes all the variables in the template.

Did this article help?


Do you need billing or technical support?