Templating an email
Written by
Updated at April 9, 2025
To send emails using a populated template, submit both the template and data to insert via the AWS CLI or API.
Getting started
- Create a service account in the folder as the address. If you create the service account and address in different folders, you will get an error when attempting to send an email.
- Assign the
postbox.sender
role to the service account. - Create a static access key. Save the ID and secret key to a secure location. You will not be able to view the secret key parameters again after you close the window.
Sending an email via the AWS CLI
-
Prepare an email template. For example, create a file named
message.json
with the following contents:{ "FromEmailAddress": "Alice <alice@example.com>", "Destination": { "ToAddresses": [ "bob@example.com", "Charlie <charlie@example.com>" ] }, "Content": { "Template": { "Headers": [ { "Name": "List-Unsubscribe", "Value": "<https://example.com/unsubscribe?user_id=sercet_hash>" }, { "Name": "List-Unsubscribe-Post", "Value": "List-Unsubscribe=One-Click" } ], "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\":\"Bob\", \"favoriteanimal\": \"bobcat\" }" } }, "ConfigurationSetName": "ConfigSet" }
-
To send an email, run this command:
aws sesv2 send-email --cli-input-json file://message.json \ --endpoint-url https://postbox.cloud.yandex.net
Note
Template use the Handlebars
syntax. When providing a template in a request, you can only use simple subsitutions. Loops, conditions, and other structures are not supported.