mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Mailgun: fix event/metadata param extraction in tracking webhook
Mailgun merges user-variables (metadata) into the webhook post data interspersed with the actual event params. This can lead to ambiguity interpreting post data. To extract metadata from an event, Anymail had been attempting to avoid that ambiguity by instead using X-Mailgun-Variables fields found in the event's message-headers param. But message-headers isn't included in some tracking events (opened, clicked, unsubscribed), resulting in empty metadata for those events. (#76) Also, conflicting metadata keys could confuse Anymail's Mailgun event parsing, leading to unexpected values in the normalized event. (#77) This commit: * Cleans up Anymail's tracking webhook to be explicit about which multi-value params it uses, avoiding conflicts with metadata keys. Fixes #77. * Extracts metadata from post params for opened, clicked and unsubscribed events. All unknown event params are assumed to be metadata. Fixes #76. * Documents a few metadata key names where it's impossible (or likely to be unreliable) for Anymail to extract metadata from the post data. For reference, the order of params in the Mailgun's post data *appears* to be (from live testing): * For the timestamp, token and signature params, any user-variable with the same name appears *before* the corresponding event data. * For all other params, any user-variable with the same name as a Mailgun event param appears *after* the Mailgun data.
This commit is contained in:
@@ -126,6 +126,20 @@ values directly to Mailgun. You can use any of the (non-file) parameters listed
|
||||
.. _Mailgun sending docs: https://documentation.mailgun.com/api-sending.html#sending
|
||||
|
||||
|
||||
.. _mailgun-quirks:
|
||||
|
||||
Limitations and quirks
|
||||
----------------------
|
||||
|
||||
**Metadata keys and tracking webhooks**
|
||||
Because of the way Mailgun supplies custom data (user-variables) to webhooks,
|
||||
there are a few metadata keys that Anymail cannot reliably retrieve in some
|
||||
tracking events. You should avoid using "body-plain", "h", "message-headers",
|
||||
"message-id" or "tag" as :attr:`~anymail.message.AnymailMessage.metadata` keys
|
||||
if you need to access that metadata from an opened, clicked, or unsubscribed
|
||||
:ref:`tracking event <event-tracking>` handler.
|
||||
|
||||
|
||||
.. _mailgun-templates:
|
||||
|
||||
Batch sending/merge and ESP templates
|
||||
|
||||
Reference in New Issue
Block a user