-
I double and triple checked my settings:
The production server perfectly delivers emails as expected. However I regularly (every couple of hours) get an email informing me of the following error:
Upon further inspection, I learned that in the body of the request there is always the same recipient, which is completely unknown to me and seems "spammy". First I thought I had misconfigured something, however now I rather believe that these requests are actually missing the required auth and are rightfully rejected. I will happily supply more information. Big thanks to the community. I love how we support each other! 🙌 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Is your production web server correctly receiving webhook tracking events for other messages you send? (If it had been working fine before and this just started recently, what else changed around that time?) If all webhooks are failing, the problem is with your configuration: your Django Anymail settings don't match what's in Mailgun's webhook dashboard:
If tracking webhooks are mostly working, and you're just getting a few that trigger the auth error, then you'll want to figure out what is posting those mis-authed webhooks:
I'd recommend figuring out where the mis-authed webhooks are coming from and solving the problem at the source. But if you just want to stop the email notifications, you could adjust your Django logging configuration to remove AdminEmailHandler (disables all error emails) or to filter out AnymailWebhookValidationFailure errors. |
Beta Was this translation helpful? Give feedback.
-
Hello Mike and thank you for getting back to me with such a wonderfully verbose response!
The error emails started on Apr 6, 2023, 7:11 PM UTC.
I am not noticing any issues other than these error emails - all with the same recipient. (more on this later)
I tried removing the WEBHOOK_SECRET as it is supposed to fallback on signing with similar security as far as I can tell from the docs.
I checked my caddy (production webserver) which is set to transparent by default and should not drop or mask any such headers.
I did not use the sandbox domain. Thanks for thinking about and checking that one as well. 👏
No, I don't.
No, the recipient is: "info@phuk****clinic.com" in every such email and it triggers daily. I can very confidently say that this email is unrelated to my project.
I sadly don't see or rather don't know where/how I would be able to see the IP address of the poster in the sentry error stack trace. 🤷♂️
Thanks for the pro-active suggestions. It even feels good to have an option like that on my mind. I will try to further find check through your suggestions. The next step I will undergo is manually testing the tracking endpoint and observing if I get the same (or similar) error message. I also find it quite confusing as I did setup everything on mailgun so that I can add tracking, however I am not sending a single email with tracking info in it, so it doubly does not make sense to me that I get these emails. I'll do the manual testing and report back. Thank you so much Mike for the steps I can go through once more. 🙏 |
Beta Was this translation helpful? Give feedback.
-
Also, since you're using Sentry… You can figure out whether the auth is "missing" or "invalid": in the Sentry stack trace, look for AnymailBasicAuthMixin.validate_request in anymail/webhooks/base.py (should be at the top). Check the value of the And if you've set up Sentry to notify you about Django errors, there's really no need to also have Django's default AdminEmailHandler in your production logging config. |
Beta Was this translation helpful? Give feedback.
-
@medmunds You were absolutely right! Sorry for taking that much time for reporting back. Thank you so much for pointing me in that direction. I don't now how to better express that than to repeat myself and appreciate how methodical and thorough and kind you have been taking the time to helping me save hours of further clueless debugging in the wrong direction. I learned from the interaction with you not just when it comes to this bug, but regarding your approach as well. 🙏🏽 I wish you a wonderful start of July! ☀️ |
Beta Was this translation helpful? Give feedback.
That IP is probably Mailgun (which uses GCP), so this is probably a legitimate webhook post from Mailgun to your server.
Is it possible you have Mailgun inbound routing set up? (That would generate the same error message, if the webhook secret was missing from the "receiving route forward url". Mailgun inbound is configured on a different dashboard page from their delivery tracking webhooks. Inbound spam with a spoofed recipient seems consistent with what you've described.)
If you remove the
ANYMAIL_WEBHOOK_SECRET
setting (and/orANYMAIL = {..., "WEBHOOK_SECRET": ...}
setting), it should not be possible to get "Missing or invalid basic auth" errors. Anymail doesn't even look at the HTTP_A…