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.67k stars 129 forks source link

Misleading error with fail_silently: "boto3 sesv2 client does not have method 'send_email'" #308

Closed technolingo closed 1 year ago

technolingo commented 1 year ago

Reporting an error? It's helpful to know:

medmunds commented 1 year ago

Thanks for the report, and for including the whole stack trace (which was essential to figure out what's going on here).

This seems to be a combination of some problems in your code or environment, plus an Anymail bug that results in misleading error messages.

First, the problems on your end:

  1. Whatever request you made to your Django server failed, with an unexpected exception. Your server is trying to respond with a 500 error.
  2. Your Django logging is set up to mail_admins to let you know about the problem. But Anymail was unable to successfully create a boto3 sesv2 client to send that mail. The most likely explanation is boto3 can't find the necessary credentials, though there could be other causes. (Have you successfully sent any email from this server?)

Django logging sends the email with fail_silently=True, so the correct behavior would be for Anymail to just ignore the configuration problems and not send any email. (And then you would hopefully discover problem 1 above in your log files.)

The Anymail bug is in the SESv2 backend: it should not be trying to post_to_esp if boto3 client creation failed and fail_silently is enabled. The "boto3 sesv2 client does not have method" error message is misleading: the actual problem is there is no client, and we should just ignore that if asked to fail_silently.

I'll fix the Anymail bug. In the meantime, I'd suggest either fixing your server settings so that Anymail is able to successfully send email through SES, or removing mail_admins from your Django logging config (if you don't want to receive email about errors).

technolingo commented 1 year ago

Hi @medmunds ,

Thank you very much for your prompt and detailed response! Indeed, I had misconfigured the boto3 environment variables. Now the issue is resolved.

Best