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

2 minute read
0

I'm using the SendTemplatedEmail operation to send messages from my Amazon Simple Email Service (Amazon SES) account. However, Amazon SES doesn't deliver some emails.

Resolution

When you use an email template, Amazon SES validates that the template data you send includes the required variables 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.

Use Amazon Simple Notification Service (Amazon SNS) to set up Rendering Failure event notifications. Review the Rendering Failure event notifications to find out why Amazon SES doesn't deliver an email when you use the SendTemplatedEmail operation.

After you set up Rendering Failure event notifications, you 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, the following 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, then Amazon SES can't deliver the email. This is because the favoritecolor variable is missing from the template.

Important: Including extra variables that aren't present in the template, such as favoritenumber, doesn't cause an error. However, all variables that you include in the template must have an exact case-sensitive counterpart in the template data. See the following example:

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

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

{
    "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"
    }
}

To avoid Rendering Failures, follow these guidelines:

  • 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.

Related information

Using templates to send personalized email with the Amazon SES API

AWS OFFICIAL
AWS OFFICIALUpdated a year ago