mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Add merge_metadata for other ESPs
Support merge_metadata in Mailgun, Mailjet, Mandrill, Postmark, SparkPost, and Test backends. (SendGrid covered in earlier PR.) Also: * Add `merge_metadata` to AnymailMessage, AnymailMessageMixin * Add `is_batch()` logic to BasePayload, for consistent handling * Docs Note: Mailjet implementation switches *all* batch sending from their "Recipients" field to to the "Messages" array bulk sending option. This allows an independent payload for each batch recipient. In addition to supporting merge_metadata, this also removes the prior limitation on mixing Cc/Bcc with merge_data. Closes #141.
This commit is contained in:
@@ -79,6 +79,9 @@ class MandrillPayload(RequestsPayload):
|
||||
|
||||
def serialize_data(self):
|
||||
self.process_esp_extra()
|
||||
if self.is_batch():
|
||||
# hide recipients from each other
|
||||
self.data['message']['preserve_recipients'] = False
|
||||
return self.serialize_json(self.data)
|
||||
|
||||
#
|
||||
@@ -163,7 +166,6 @@ class MandrillPayload(RequestsPayload):
|
||||
self.data.setdefault("template_content", []) # Mandrill requires something here
|
||||
|
||||
def set_merge_data(self, merge_data):
|
||||
self.data['message']['preserve_recipients'] = False # if merge, hide recipients from each other
|
||||
self.data['message']['merge_vars'] = [
|
||||
{'rcpt': rcpt, 'vars': [{'name': key, 'content': rcpt_data[key]}
|
||||
for key in sorted(rcpt_data.keys())]} # sort for testing reproducibility
|
||||
@@ -176,6 +178,13 @@ class MandrillPayload(RequestsPayload):
|
||||
for var, value in merge_global_data.items()
|
||||
]
|
||||
|
||||
def set_merge_metadata(self, merge_metadata):
|
||||
# recipient_metadata format is similar to, but not quite the same as, merge_vars:
|
||||
self.data['message']['recipient_metadata'] = [
|
||||
{'rcpt': rcpt, 'values': rcpt_data}
|
||||
for rcpt, rcpt_data in merge_metadata.items()
|
||||
]
|
||||
|
||||
def set_esp_extra(self, extra):
|
||||
# late bind in serialize_data, so that obsolete Djrill attrs can contribute
|
||||
self.esp_extra = extra
|
||||
|
||||
Reference in New Issue
Block a user