Skip to content

[Proposal][Mailgun][webhooks] change event_types and reject_reason mappings #130

@costela

Description

@costela

Currently, it seems impossible to differentiate temporary from permanent failures by analyzing AnymailTrackingEvent created by the mailgun webhook.
A delivery which had a temporary failure due to - for instance - a broken connection, will generate a webhook payload with (among other fields):

{
  "event": "failed",
  "reason": "generic",
  "severity": "temporary"
}

This gets mapped to a AnymailTrackingEvent with event_type=BOUNCED and reject_reason=BOUNCED, which is hardly helpful. In particular, in the case of a failed connection, it feels actually misleading, IMHO, since there was no actual bounce from the receiving server.

Looking at anymail/webhooks/mailgun.py, I'd suggest doing something like the following in esp_to_anymail_event():

if event_type == EventType.BOUNCED and event_data['severity'] == 'temporary':
  event_type = EventType.DEFERRED

Also, changing the reject_reasons mapping from generic → BOUNCED to generic → OTHER. The rationale being: if Mailgun cannot interpret the error, we shouldn't assume it has any particular type.

Additionally, and mostly unrelated, we also see "reason": "greylisted" in our logs, which is currently not handled at all and might be mapped to BOUNCED?

Before working on a concrete PR, I thought I get some opinions on this. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions