如何使用 aws pinpoint 发送带有自定义模板的电子邮件

How to send an email with a custom template using aws pinpoint

我正在尝试发送带有模板的电子邮件,但收到此错误消息:

Unknown parameter in Content: "Template", must be one of: Simple, Raw

我遵循了这个 link:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/pinpoint-email.html#PinpointEmail.Client.send_email 这是我的代码:

client = boto3.client('pinpoint-email', region_name=AWS_REGION)

response = client.send_email(

    FromEmailAddress=SENDER,
    Destination={
        'ToAddresses': TOADDRESSES
    },
    Content={
        'Simple': {
            'Subject': {
                'Charset': CHARSET,
                'Data': "SUBJECT",
            },
            'Body': {
                'Html': {
                    'Charset': CHARSET,
                    'Data': "BODY_HTML"
                },
                'Text': {
                    'Charset': CHARSET,
                    'Data': "BODY_TEXT",
                }
            }
        },
        'Template': {
            'TemplateArn': TEMPLATE_ARN,
            'TemplateData': json.dumps(TEMPLATE_DATA)
        }
    }
)

使用 Python (Boto 3) 版本 1.9.62 和 Python 版本 3.6.7 的 SDK 进行测试。

AWS_REGION = 'ap-southeast-2'
SENDER = 'sentFrom@email.com'
TOADDRESSES = ['sendTo@email.co']
TEMPLATE_ARN = 'arn:aws:mobiletargeting:ap-southeast-2:1234567890:templates/MessageTemplate-Test01/EMAIL'
TEMPLATE_DATA = {
    "FirstName": "555 name",
    "Activity": "doing things",
    "PersonalRecord": "1.234",
    "EmailSubject": "Time to Race 123"
}

client_pinpoint = boto3.client('pinpoint-email', region_name=AWS_REGION)
response_pinpoint = client_pinpoint.send_email(
    FromEmailAddress=SENDER,
    Destination={'ToAddresses': TOADDRESSES},
    Content={'Template': {'TemplateArn': TEMPLATE_ARN, "TemplateData": json.dumps(TEMPLATE_DATA)}})

print(response_pinpoint)