Skip to content

Mailgun: certain metadata keys can break tracking webhooks #77

@medmunds

Description

@medmunds

[Discovered while investigating #76]

Because of the way Mailgun merges user-variables into its webhook posts, using metadata keys that conflict with Mailgun event parameters can confuse Anymail's event parsing and lead to unexpected results. For example, if you send this message:

    AnymailMessage(
        # ...
        to=["customer@example.com"],
        metadata={"event": "holiday campaign", "recipient": "vip"}
    ).send()

The the tracking handler will receive incorrect information for all tracking events (because "event" and "recipient" are Mailgun event parameters):

    @receiver(tracking)
    def handle_event(sender, event, esp_name, **kwargs):
        # the event_type should be "received" or "opened", etc., but...
        print(event.event_type)  # "unknown" (for every event about this message)
        # the recipient should be "customer@example.com", but...
        print(event.recipient)  # "vip"

It looks like Mailgun supplies both its event parameter field and the user-variable field in the post data, so they're both available in Django's POST QueryDict:

        print(event.esp_event.getlist('recipient'))  # ["customer@example.com", "vip"]

Just need to figure out how to reliably split Mailgun's event params from the metadata ones. (The merge order is not consistent between fields.)

Affects all versions of Anymail through 1.0.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions