A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html below:

Using templates to send personalized email with the Amazon SES API

Using templates to send personalized email with the Amazon SES API

In Amazon SES you can send templated email either by using a stored template or by using an inline template.

The following limits apply when using stored templates:

The following limit applies when using inline templates:

The following applies to both stored and inline templates:

This chapter includes procedures with examples for using both stored templates and inline templates.

Note

The procedures in this section assume that you've already installed and configured the AWS CLI. For more information about installing and configuring the AWS CLI, see the AWS Command Line Interface User Guide.

(Optional) Part 1: Set up Rendering Failure event notifications

If you send an email that contains invalid personalization content, Amazon SES might accept the message, but won't be able to deliver it. For this reason, if you plan to send personalized email, you should configure SES to send Rendering Failure event notifications through Amazon SNS. When you receive a Rendering Failure event notification, you can identify which message contained the invalid content, fix the issues, and send the message again.

The procedure in this section is optional, but highly recommended.

To configure Rendering Failure event notifications
  1. Create an Amazon SNS topic. For procedures, see Create a Topic in the Amazon Simple Notification Service Developer Guide.

  2. Subscribe to the Amazon SNS topic. For example, if you want to receive Rendering Failure notifications by email, subscribe an email endpoint (that is, your email address) to the topic.

    For procedures, see Subscribe to a Topic in the Amazon Simple Notification Service Developer Guide.

  3. Complete the procedures in Set up an Amazon SNS event destination for event publishing to set up your configuration sets to publish Rendering Failure events to your Amazon SNS topic.

(Optional) Part 2: Create an email template

If you intend on using a stored template, this section will show you how to use the CreateEmailTemplate SES v2 API operation to create the template. You can skip this step if you want to use an inline template.

This procedure assumes that you've already installed and configured the AWS CLI. For more information about installing and configuring the AWS CLI, see the AWS Command Line Interface User Guide.

To create the template
  1. In a text editor, create a new file and paste the following code customizing it as you need.

    {
        "TemplateName": "MyTemplate",
        "TemplateContent": {
            "Subject": "Greetings, {{name}}!",
            "Text": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.",
            "Html": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>"
        }
    }

    This code contains the following properties:

  2. Customize the preceding example to fit your needs, and then save the file as mytemplate.json.

  3. At the command line, type the following command to create a new template using the CreateEmailTemplate v2 API operation:

    aws sesv2 create-email-template --cli-input-json file://mytemplate.json
Part 3: Sending the personalized email

You can use the following two SES v2 API operations to send emails using either stored templates or inline templates:

This section provides examples of how to use the AWS CLI to send templated email using both of these send operations.

Sending templated email to a single destination object

You can use the SendEmail operation to send an email to one or more recipients defined in a single destination object. All of the recipients in the Destination object will receive the same email.

To send a templated email to a single destination object
  1. Depending on whether you want to use a stored template or inline template, select the respective code example to paste into a text editor, customizing it as you need.

    Stored template code example

    Notice that the template you created in the previous step, MyTemplate, is being referenced as the value for the TemplateName parameter.

    {
        "FromEmailAddress": "Mary Major <mary.major@example.com>",
        "Destination": {
            "ToAddresses": [
                "alejandro.rosalez@example.com", "jimmy.jet@example.com"
            ]
        },
        "Content": {
            "Template": {
                "TemplateName": "MyTemplate",
                "TemplateData": "{ \"name\":\"Alejandro\", \"favoriteanimal\": \"alligator\" }"
            }
        },
        "ConfigurationSetName": "ConfigSet"
    }

    This code contains the following properties:

    • FromEmailAddress – The email address of the sender.

    • Destination – An object containing the email recipients defined in the ToAddresses, CcAddresses, and BccAddresses properties. These can be used in any combination and can contain one or more email addresses that will receive the same email.

    • TemplateName – The name of the Template resource to apply to the email.

    • TemplateData – An escaped JSON string that contains key-value pairs. The keys correspond to the variables defined in the TemplateContent properties in the stored template, for example, {{name}}. The values represent the content that replaces the variables.

    • ConfigurationSetName – The name of the configuration set to use when sending the email.

    Inline template code example

    Notice that the TemplateContent properties (that would normally be defined in a stored template), are being defined inline along with the TemplateData property which makes this an inline template.

    {
        "FromEmailAddress": "Mary Major <mary.major@example.com>",
        "Destination": {
            "ToAddresses": [
                "alejandro.rosalez@example.com", "jimmy.jet@example.com"
            ]
        },
        "Content": {
            "Template": {
                "TemplateContent": {
                    "Subject": "Greetings, {{name}}!",
                    "Text": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.",
                    "Html": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>"
                },
                "TemplateData": "{ \"name\":\"Alejandro\", \"favoriteanimal\": \"alligator\" }"
            }
        },
        "ConfigurationSetName": "ConfigSet"
    }

    This code contains the following properties:

    • FromEmailAddress – The email address of the sender.

    • Destination – An object containing the email recipients defined in the ToAddresses, CcAddresses, and BccAddresses properties. These can be used in any combination and can contain one or more email addresses that will receive the same email.

    • TemplateContent – A container for the following attributes:

      • SubjectPart – The subject line of the email. This property may contain replacement tags. These tags use the following format: {{tagname}}. When you send the email, you can specify a value for tagname for each destination.

      • HtmlPart – The HTML body of the email. This property may contain replacement tags. The preceding example includes two tags: {{name}} and {{favoriteanimal}}.

      • TextPart – The text body of the email. Recipients whose email clients don't display HTML content will see this version of the email. This property may also contain replacement tags.

    • TemplateData – An escaped JSON string that contains key-value pairs. The keys correspond to the variables defined in the TemplateContent properties in this file, for example, {{name}}. The values represent the content that replaces the variables.

    • ConfigurationSetName – The name of the configuration set to use when sending the email.

  2. Customize the preceding example to fit your needs, and then save the file as myemail.json.

  3. At the command line, type the following v2 API command to send the email:

    aws sesv2 send-email --cli-input-json file://myemail.json
Sending templated email to multiple destination objects

You can use the SendBulkEmail operation to send an email to multiple destination objects in a single call to the SES v2 API. SES sends a unique email to the recipient or recipients in each Destination object.

To send a templated email to multiple destination objects
  1. Depending on whether you want to use a stored template or inline template, select the respective code example to paste into a text editor, customizing it as you need.

    Stored template code example

    Notice that the template you created in the previous step, MyTemplate, is being referenced as the value for the TemplateName parameter.

    {
        "FromEmailAddress": "Mary Major <mary.major@example.com>",
        "DefaultContent": {
            "Template": {
                "TemplateName": "MyTemplate",
                "TemplateData": "{ \"name\":\"friend\", \"favoriteanimal\":\"unknown\" }"
            }
        },
        "BulkEmailEntries": [
            {
                "Destination": {
                    "ToAddresses": [
                        "anaya.iyengar@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{ \"name\":\"Anaya\", \"favoriteanimal\":\"angelfish\" }"
                    }
                }
            },
            {
                "Destination": {
                    "ToAddresses": [
                        "liu.jie@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{ \"name\":\"Liu\", \"favoriteanimal\":\"lion\" }"
                    }
                }
            },
            {
                "Destination": {
                    "ToAddresses": [
                        "shirley.rodriguez@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{ \"name\":\"Shirley\", \"favoriteanimal\":\"shark\" }"
                    }
                }
            },
            {
                "Destination": {
                    "ToAddresses": [
                        "richard.roe@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{}"
                    }
                }
            }
        ],
        "ConfigurationSetName": "ConfigSet"
    }

    This code contains the following properties:

    • FromEmailAddress – The email address of the sender.

    • DefaultContent – A JSON object that contains the TemplateName and TemplateData objects.

    • TemplateName – The name of the Template resource to apply to the email.

    • TemplateData – Contains key-value pairs that will be used if the ReplacementEmailContent object contains an empty JSON object, {}, in the ReplacementTemplateData property.

    • BulkEmailEntries – An array that contains one or more Destination objects.

    • Destination – An object containing the email recipients defined in the ToAddresses, CcAddresses, and BccAddresses properties. These can be used in any combination and can contain one or more email addresses that will receive the same email.

    • ReplacementTemplateData – An escaped JSON string that contains key-value pairs. The keys correspond to the variables in the template, for example, {{name}}. The values represent the content that replaces the variables in the email. (If the JSON string here is empty, indicated by {}, the key-value pairs defined in the TemplateData property within the DefaultContent object will be used.)

    • ConfigurationSetName – The name of the configuration set to use when sending the email.

    Inline template code example

    Notice that the TemplateContent properties (that would normally be defined in a stored template), are being defined inline along with the TemplateData property which makes this an inline template.

    {
        "FromEmailAddress": "Mary Major <mary.major@example.com>",
        "DefaultContent": {
            "Template": {
                "TemplateContent": {
                    "Subject": "Greetings, {{name}}!",
                    "Text": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.",
                    "Html": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>"
                },
                "TemplateData": "{ \"name\":\"friend\", \"favoriteanimal\":\"unknown\" }"
            }
        },
        "BulkEmailEntries": [
            {
                "Destination": {
                    "ToAddresses": [
                        "anaya.iyengar@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{ \"name\":\"Anaya\", \"favoriteanimal\":\"angelfish\" }"
                    }
                }
            },
            {
                "Destination": {
                    "ToAddresses": [
                        "liu.jie@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{ \"name\":\"Liu\", \"favoriteanimal\":\"lion\" }"
                    }
                }
            },
            {
                "Destination": {
                    "ToAddresses": [
                        "shirley.rodriguez@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{ \"name\":\"Shirley\", \"favoriteanimal\":\"shark\" }"
                    }
                }
            },
            {
                "Destination": {
                    "ToAddresses": [
                        "richard.roe@example.com"
                    ]
                },
                "ReplacementEmailContent": {
                    "ReplacementTemplate": {
                        "ReplacementTemplateData": "{}"
                    }
                }
            }
        ],
        "ConfigurationSetName": "ConfigSet"
    }

    This code contains the following properties:

    • FromEmailAddress – The email address of the sender.

    • DefaultContent – A JSON object that contains the TemplateContent and TemplateData objects.

    • TemplateContent – A container for the following attributes:

      • SubjectPart – The subject line of the email. This property may contain replacement tags. These tags use the following format: {{tagname}}. When you send the email, you can specify a value for tagname for each destination.

      • HtmlPart – The HTML body of the email. This property may contain replacement tags. The preceding example includes two tags: {{name}} and {{favoriteanimal}}.

      • TextPart – The text body of the email. Recipients whose email clients don't display HTML content will see this version of the email. This property may also contain replacement tags.

    • TemplateData – Contains key-value pairs that will be used if the ReplacementEmailContent object contains an empty JSON object, {}, in the ReplacementTemplateData property.

    • BulkEmailEntries – An array that contains one or more Destination objects.

    • Destination – An object containing the email recipients defined in the ToAddresses, CcAddresses, and BccAddresses properties. These can be used in any combination and can contain one or more email addresses that will receive the same email.

    • ReplacementTemplateData – An escaped JSON string that contains key-value pairs. The keys correspond to the variables defined in the TemplateContent properties in this file, for example, {{name}}. The values represent the content that replaces the variables in the email. (If the JSON string here is empty, indicated by {}, the key-value pairs defined in the TemplateData property within the DefaultContent object will be used.)

    • ConfigurationSetName – The name of the configuration set to use when sending the email.

  2. Change the values in the code in the previous step to meet your needs, and then save the file as mybulkemail.json.

  3. At the command line, type the following v2 API command to send the bulk email:

    aws sesv2 send-bulk-email --cli-input-json file://mybulkemail.json

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4