anymail / django-anymail

Django email backends and webhooks for Amazon SES, Brevo (Sendinblue), MailerSend, Mailgun, Mailjet, Postmark, Postal, Resend, SendGrid, SparkPost, Unisender Go and more
https://anymail.dev
BSD 3-Clause "New" or "Revised" License
1.65k stars 125 forks source link

Resend: confusing ReadTimeout error for incorrect API key #346

Closed medmunds closed 8 months ago

medmunds commented 8 months ago

[If you get a ReadTimeout trying to send through Resend.com, it could be an invalid API key.]

If your ANYMAIL setting RESEND_API_KEY is wrong (or expired), trying to send a message will result a ReadTimeout error (near the end of the stack):

anymail.backends.base_requests.AnymailRequestsAPIError: 
  Error posting to https://api.resend.com/emails:
  requests.exceptions.ReadTimeout: 
  HTTPSConnectionPool(host='api.resend.com', port=443): Read timed out. (read timeout=30)

This is due to a Resend API change sometime between 2023-12-07 and 2023-12-14. Previously, Resend responded with a helpful "API key is invalid" 403 error—and this is still Resend's documented behavior). But now, Resend's API simply ignores bad/expired/missing API keys and never responds, leading to the timeout.

[This isn't Anymail's bug, but was caught by our integration tests. The new behavior has been reported to Resend. Test disabled in 2cadb949cd7a965116bb1848bcf09631c218cf8a (hopefully temporarily).]