Search code examples
amazon-web-servicesaws-cliamazon-ses

How to send AWS templated email from cli


I am trying to send templated email with command:

aws ses send-templated-email --source "temp@gmail.com" --destination "ToAddresses=example@gmail.com" --template-data "{ "firstName": "temp", "lastName": "temp" }" --cli-input-json file://temp.json

but I do not know why I get the following error

Invalid type for parameter Template, value: {'TemplateName': 'temp', 'SubjectPart': 'Greetings!', 'HtmlPart': '<h3>Dear {{firstName}} {{lastName}}</h3>', 'TextPart': ''}, type: <class 'dict'>, valid types: <class 'str'>

The template file content is exactly like this

{
    "Template": {
        "TemplateName": "temp",
        "SubjectPart": "Greetings!",
        "HtmlPart": "<h3>Dear {{firstName}} {{lastName}}</h3>",
        "TextPart": ""
    }
}

I do not know what I am doing wrong. How it should be correcltly done with send-templated-email command?


Solution

  • You need to create the template first with aws ses create-template. You can't specify the template at runtime. After you create the template, you would reference the data like this:

    aws ses send-templated-email --cli-input-json file://template-values.json

    With template-values.json looking something like:

    {
      "Source": "<temp@gmail.com>",
      "Template": "temp",
      "Destination": {
        "ToAddresses": ["example@gmail.com"]
      },
      "TemplateData": "{ \"firstName\":\"temp\", \"lastName\": \"temp\" }"
    }
    
    

    AWS Ref