mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Add merge_headers option for Amazon SES
Add new `merge_headers` message option for per-recipient headers with template sends. * Support in base backend * Implement in Amazon SES backend (Requires boto3 >= 1.34.98.) --------- Co-authored-by: Mike Edmunds <medmunds@gmail.com>
This commit is contained in:
committed by
GitHub
parent
4c62f7bee0
commit
33f680686b
@@ -298,6 +298,9 @@ class AmazonSESV2SendEmailPayload(AmazonSESBasePayload):
|
||||
# metadata.
|
||||
self.mime_message["X-Metadata"] = self.serialize_json(metadata)
|
||||
|
||||
def set_merge_headers(self, merge_headers):
|
||||
self.unsupported_feature("merge_headers without template_id")
|
||||
|
||||
def set_tags(self, tags):
|
||||
# See note about Amazon SES Message Tags and custom headers in set_metadata
|
||||
# above. To support reliable retrieval in webhooks, use custom headers for tags.
|
||||
@@ -339,6 +342,7 @@ class AmazonSESV2SendBulkEmailPayload(AmazonSESBasePayload):
|
||||
# late-bind recipients and merge_data in finalize_payload
|
||||
self.recipients = {"to": [], "cc": [], "bcc": []}
|
||||
self.merge_data = {}
|
||||
self.merge_headers = {}
|
||||
|
||||
def finalize_payload(self):
|
||||
# Build BulkEmailEntries from recipients and merge_data.
|
||||
@@ -355,8 +359,9 @@ class AmazonSESV2SendBulkEmailPayload(AmazonSESBasePayload):
|
||||
]
|
||||
|
||||
# Construct an entry with merge data for each "to" recipient:
|
||||
self.params["BulkEmailEntries"] = [
|
||||
{
|
||||
self.params["BulkEmailEntries"] = []
|
||||
for to in self.recipients["to"]:
|
||||
entry = {
|
||||
"Destination": dict(ToAddresses=[to.address], **cc_and_bcc_addresses),
|
||||
"ReplacementEmailContent": {
|
||||
"ReplacementTemplate": {
|
||||
@@ -366,8 +371,13 @@ class AmazonSESV2SendBulkEmailPayload(AmazonSESBasePayload):
|
||||
}
|
||||
},
|
||||
}
|
||||
for to in self.recipients["to"]
|
||||
]
|
||||
|
||||
if len(self.merge_headers) > 0:
|
||||
entry["ReplacementHeaders"] = [
|
||||
{"Name": key, "Value": value}
|
||||
for key, value in self.merge_headers.get(to.addr_spec, {}).items()
|
||||
]
|
||||
self.params["BulkEmailEntries"].append(entry)
|
||||
|
||||
def parse_recipient_status(self, response):
|
||||
try:
|
||||
@@ -490,6 +500,10 @@ class AmazonSESV2SendBulkEmailPayload(AmazonSESBasePayload):
|
||||
# late-bound in finalize_payload
|
||||
self.merge_data = merge_data
|
||||
|
||||
def set_merge_headers(self, merge_headers):
|
||||
# late-bound in finalize_payload
|
||||
self.merge_headers = merge_headers
|
||||
|
||||
def set_merge_global_data(self, merge_global_data):
|
||||
# DefaultContent.Template.TemplateData
|
||||
self.params.setdefault("DefaultContent", {}).setdefault("Template", {})[
|
||||
|
||||
Reference in New Issue
Block a user