Possible to have duplicate email addresses in merge_data with different fields? #279
-
| Normally I would construct the  For example I'm getting a values list like this: And converting them to a dict in the right format for  buyers = {}
for buyer in self.buyers:
    buyers[buyer[1]] = {'name': buyer[0], 'order_code': buyer[2]}
return buyersHowever in this instance I have duplicate emails due to different orders and need each one to get an email with different metadata but basically the same  Thank you for any assistance! 😃 | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
| Short answer: no, if you want to send two messages with different merge data to the same email address, you'll need to do that as two separate sends, not a single batch send. Longer answer: this is a limitation in Anymail's batch sending. Anymail's  Postmark's batch send API (and it looks like every other ESP except Mailgun) actually allows the same recipient to appear multiple times with different data, generating multiple messages to the same recipient. But there's not a way to communicate that to Anymail through  Since repeat batch recipients are so widely supported, it might be nice to add this to Anymail. It's a little tricky, because Django's EmailMessage object isn't really a great match for describing a batch send. (Really, a batch should take a list of EmailMessage objects, but that's a whole other can of worms.) If we stick with the EmailMessage's  | 
Beta Was this translation helpful? Give feedback.
Short answer: no, if you want to send two messages with different merge data to the same email address, you'll need to do that as two separate sends, not a single batch send.
Longer answer: this is a limitation in Anymail's batch sending. Anymail's
merge_datais structured as a dict keyed by recipient email, which means each recipient address can only appear once in it. (Unless you play games with case sensitivity, which, please don't. BTW, Anymail inherited themerge_datadict approach from the predecessor Djrill project.)Postmark's batch send API (and it looks like every other ESP except Mailgun) actually allows the same recipient to appear multiple times with different data, generatin…