mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
SparkPost: work around json recipients problem
python-sparkpost generates a transmissions.send payload which is now considered invalid by the API, if you try to use both `cc` (or `bcc`) and the `recipients` dict structure required for merge_data. [Anymail had been generating that recipients dict structure in all cases, for simplicity. Sometime between 2016-06-07 and 2016-06-22, SparkPost began rejecting that if it appeared in the `header_to` constructed by python-sparkpost.]
This commit is contained in:
@@ -87,15 +87,20 @@ class SparkPostPayload(BasePayload):
|
||||
def get_api_params(self):
|
||||
# Compose recipients param from to_emails and merge_data (if any)
|
||||
recipients = []
|
||||
for email in self.to_emails:
|
||||
rcpt = {'address': {'email': email.email}}
|
||||
if email.name:
|
||||
rcpt['address']['name'] = email.name
|
||||
try:
|
||||
rcpt['substitution_data'] = self.merge_data[email.email]
|
||||
except KeyError:
|
||||
pass # no merge_data or none for this recipient
|
||||
recipients.append(rcpt)
|
||||
if len(self.merge_data) > 0:
|
||||
# Build JSON recipient structures
|
||||
for email in self.to_emails:
|
||||
rcpt = {'address': {'email': email.email}}
|
||||
if email.name:
|
||||
rcpt['address']['name'] = email.name
|
||||
try:
|
||||
rcpt['substitution_data'] = self.merge_data[email.email]
|
||||
except KeyError:
|
||||
pass # no merge_data or none for this recipient
|
||||
recipients.append(rcpt)
|
||||
else:
|
||||
# Just use simple recipients list
|
||||
recipients = [email.address for email in self.to_emails]
|
||||
if recipients:
|
||||
self.params['recipients'] = recipients
|
||||
|
||||
|
||||
Reference in New Issue
Block a user