anymail / django-anymail

Django email backends and webhooks for Amazon SES, Brevo (Sendinblue), MailerSend, Mailgun, Mailjet, Postmark, Postal, Resend, SendGrid, SparkPost, Unisender Go and more
https://anymail.dev
BSD 3-Clause "New" or "Revised" License
1.65k stars 125 forks source link

SendGrid: better handling of event="dropped", reason="Bounced Address" webhook events. #379

Closed vitaliyf closed 2 months ago

vitaliyf commented 2 months ago

According https://www.twilio.com/docs/sendgrid/for-developers/tracking-events/event#dropped the correct "reason" value for bouncing addresses is "Bounced Address" and that seems to be what I am seeing in SendGrid logs. Without this change those events were being normalized by anymail to type=dropped, reject_reason=other and not reject_reason=bounced.

I used sample event from their docs, and kept original mapping value since I'm not sure if that may actually show up in other situations.

medmunds commented 2 months ago

Thanks for this.

The tests are all based on actual webhook payloads observed when SendGrid support was first implemented (because the specific payload values weren't documented). It seems like they've added some values since then, but I agree it doesn't hurt to keep supporting the old "bounced" reason as well.

vitaliyf commented 2 months ago

Thank you for this project - I was only making tweaks in an inherited codebase, and it was great to discover that we used this nice library that encapsulates such secondary functionality as webhook handling.