I have a contact list, with each contact having the "Name" attribute, such as:
{
"ContactListName": "myusers",
"EmailAddress": "john@gmail.com",
"UnsubscribeAll": false,
"TopicPreferences": [
{
"TopicName": "Announcements",
"SubscriptionStatus": "OPT_IN"
}
],
"AttributesData": "{\"Name\": \"John\"}"
}
I would like send an email to all customers interested in a particular topic. The email is based on a template that begins with "Dear {{Name}}". I want {{Name}}
to be replaced with the name from the AttributesData
of each contact.
I can obtain the list of contacts interested in the topic using list_contacts. However, the response does not contain the AttributeData
and so I have to send the email like this:
response = ses_client.send_bulk_email(
FromEmailAddress='no-reply@mysite.xyz',
ReplyToAddresses=[
'feedback@mysite.xyz',
],
DefaultContent={
'Template': {
'TemplateName': 'mytemplate',
'TemplateData': '{"Name":"Unknown"}'
}
},
BulkEmailEntries=[
{
'Destination': {
'ToAddresses': [
'john@gmail.com',
],
},
'ReplacementEmailContent': {
'ReplacementTemplate': {
'ReplacementTemplateData': '{"Name":"John"}'
}
}
},
],
)
If I skip the ReplacementEmailContent
key, {{Name}}
in the template is substituted for Unknown. How do I get it to use the contact's attribute data? (Note that calling get_contact
for each contact would take too long when sending bulk email to many users)
P.S. The question in SO