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

Brevo Webhook Mapping Updates #385

Closed originell closed 1 month ago

originell commented 1 month ago

Dear Team, first of all: great package. Been using it forever without a fail. Forever grateful!

While debugging an issue with the Brevo (ex SendInBlue) Webhooks, I've discovered 2 slightly related things I'd like to get your opinions about.

A) New Events PR

I noticed that Brevo now has a couple of new events that are not yet mapped in the webhook.

From what I've seen their docs, the new ones are:

I would suggest the following mapping updates:

If these seem OK to you as well, I'd be happy to supply a PR as well. Just wanted to get a quick OK before investing the time :)

B) The "request" Event Question

Looking at the webhook view's event type mapping, I see this mapping here:

    event_types = {
# ...
        "request": (EventType.QUEUED, None),
# ...
    }

I was wondering why this is mapped to QUEUED and not SENT? If you can still remember.

The current docs seem to suggest that the request payload is meant as sent.


Thank you for taking the time maintaining this great package and also keeping the code as neat as it is!

medmunds commented 1 month ago

Thanks for catching these new Brevo events. Yes, a PR would be welcome. Your proposed mapping looks correct to me.

As to why "request" is mapped to QUEUED rather than SENT, I believe it's because "request" can be received even if Brevo doesn't actually plan to send the message. E.g., if the recipient is on Brevo's blocklist because a previous message to that address bounced or received a spam complaint, Brevo will send a "request" event immediately followed by a "blocked" event, without attempting to send the message. Anymail's EventType.SENT is supposed to be used only for messages that have truly been sent. (There's a comment alluding to that on the line above the "request" mapping. It used to be on the same line, but the Black formatter moved it and it's not so clear what it means now.)

originell commented 1 month ago

Ahhhhh! Thanks for explaining.

I definitely did not catch this relation at first glance, but it makes complete sense.

Ok great, then I'll take care of creating a PR :)

medmunds commented 2 weeks ago

(Released in Anymail 11.1. Thanks again!)

originell commented 2 weeks ago

(Amazing! Thank you for making it easy)