Skip to content

Modified custom_arg message_id for compatibility with SendGrid webhook #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 30, 2018
Merged

Modified custom_arg message_id for compatibility with SendGrid webhook #109

merged 5 commits into from
May 30, 2018

Conversation

joshkersey
Copy link
Contributor

Based our discussion in #108.

According to SendGrid support, the Message-ID and smtp-id are both used by SendGrid to set their unique message ID. Based on the conversation with SendGrid support we should use a custom arg with a key named something other than Message-ID or smtp-id.

Tried to set this up to ensure backwards compatibility for users who upgrade so that the smtp-id still gets referenced if the anymail-id is not present in the webhook data.

Copy link
Contributor

@medmunds medmunds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this -- it looks great. A few minor comments inline.

We should also update test_sendgrid_webhooks to switch to the new anymail_id field, and to cover the original problem case, where SendGrid gives the webhook a different smtp-id.

# record, we can supply the 'smtp-id' field for any events missing it.
self.data.setdefault("custom_args", {})["smtp-id"] = self.message_id
# Set anymail-id to track our custom message ID
self.data.setdefault("custom_args", {})["anymail-id"] = self.message_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd maybe go with "anymail_id" (underscore), to parallel all other webhook data fields. ("smtp-id" is the outlier.)

@@ -69,10 +69,12 @@ def esp_to_anymail_event(self, esp_event):
else:
metadata = {}

anymail_id = esp_event.get('anymail-id', None)
smtp_id = esp_event.get('smtp-id', None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified to message_id = esp_event.get('anymail_id', esp_event.get('smtp-id')).
(Use 'anymail_id' if present, else use 'smtp-id' for backwards compatibility.)

@joshkersey
Copy link
Contributor Author

Updated based on further discussion in #108. Removed a concern for Message-ID from the SendGrid and SendGrid V2 backends in favor of setting a UUID as anymail_id for tracking webhook notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants