-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support merge_headers in Amazon SES bulk send #371
Conversation
Please let me know if any change is needed in order to merge it! Just a quick note, by the time I implemented the headers, there was no published boto3 packages with this functionality, I had to install de latest version from github.
Thanks a lot for your time! |
Thanks for this! Yes, very relevant with the need for List-Unsubscribe headers. Two requests:
Also, it would be good to test merge_headers in the Amazon SES integration tests, but this will need to wait for a boto3 release that supports them. I can look into supporting merge_headers for other ESPs, too. It seems like Brevo, Mailjet, Postmark, Resend, and Sendgrid all have reasonably-easy support for per-recipient headers in their batch APIs. Unisender Go supports them (using substitutions), but only for the List-Unsubscribe header. Mailgun may or may not support them. (I can't tell from Mailgun's docs if their "replacement variables" work in header values; will need to test.) |
Thanks a lot for your feedback @medmunds! I made the changes as requested. Let me know any additional modification! |
Excellent, thanks. Sorry, one more thing: just noticed this is expecting the message = AnymailMessage(
...,
headers={
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
},
merge_headers={
"alice@example.com": {
"List-Unsubscribe": "<https://example.com/a/>",
},
"nobody@example.com": {
"List-Unsubscribe": "<mailto:unsubscribe@example.com>",
},
},
) [Btw, we try to use example.com or a similar reserved example or test domain. xyz.com is an actual domain that belongs to someone.] |
@medmunds pushed the changes as requested. I did not use headers fields, I got this error:
code
Let me know if i'm missing something. |
I think my suggestion may have been unclear. I believe the new merge_headers={
"alice@example.com": {
# not a list, just a dict of field: value
"List-Unsubscribe": "<https://example.com/a/>",
"X-Some-Other-Header": "some-other-value",
},
"nobody@example.com": {
"List-Unsubscribe": "<mailto:unsubscribe@example.com>",
},
}, This gives it the same structure as Django's own email Then in the SES finalize_payload implementation, we would convert that dict to the list format ses::SendBulkEmail requires. Something like: if to.addr_spec in self.merge_headers:
entry["ReplacementHeaders"] = [
{"Name": key, "Value": value}
for key, value in self.merge_headers[to.addr_spec].items()
] Does that seem reasonable? As for this error…
…that's this code. Because when it was first implemented, there wasn't a way to pass any email headers to ses::SendBulkEmail. We could support it now, using ReplacementHeaders. I can add that at some point later, or if you're interested, the idea is that the ReplacementHeaders for each recipient would be the merger of any extra_headers (for all recipients) plus any merge_headers (for that recipient). |
@medmunds sorry for the misunderstanding, I updated the code to a dict of dicts.
I would try to add a new PR supporting this feature 💪 Hope is ready to merge! have a great day! |
- Change in the name of the method that sets the template headers - Change in SES backend, made template headers optional for backward compatibility.
Excellent! Thanks again for this—very nice addition. I'll open a couple of issues to track related work. |
Please check ReplacementHeaders
https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendBulkEmail.html
This headers are very useful for the new requirements of email clients like gmail, yahoo, etc.
Allows to add headers as a template. This enables, for example, to add an unique unique unsubscribe header for each email.