Closed andraantariksa closed 4 months ago
Hmm, I'm not sure what's happening here. Everything looks OK to me in the code you've shown. (And it's a clever way to convert Mailgun special headers from your existing code into SES params.)
Your shell example shows the SESv2 client was created successfully and does have a send_email
function as expected. (<bound method ... of <botocore.client.SESV2 object ...>>
is the correct value for c.client.send_email
. In the shell, you could call it using c.client.send_email(params...)
.)
Some ideas to check:
Is there any reason your shell test could be different from the environment where you're getting the error? Maybe different boto3 credentials or region?
Is there any other code in your custom SESBackend? (Anything that might be altering its client
attribute?)
Does this happen on every attempt to send, or do some sends work? Has this worked before and is broken now, or is this new code? (Standard debugging questions—apologies if you've already worked through this.)
To get more info, you might try wrapping the post_to_esp
method to capture more info—in particular, what's actually in self.client at the time:
class SESBackend(AnymailBackend):
def post_to_esp(self, payload, message):
try:
getattr(self.client, payload.api_name)
except AttributeError:
# Include repr(self.client) in the error message:
raise NotImplementedError(
f"{self.client!r} does not have attr {payload.api_name!r}."
) from None
return super().post_to_esp(payload, message)
def build_message_payload(self, message: Any, defaults: Any) -> Any:
...
If self.client ends up being None—or anything other than a botocore.client.SESV2 object—that might suggest some other places to look.
Btw (unrelated to your issue), you can supply the SES ConfigurationSetName directly in your settings.py ANYMAIL dict if you prefer, rather than using esp_extra (docs):
ANYMAIL = {
...,
"AMAZON_SES_CONFIGURATION_SET_NAME": "<name>",
}
@andraantariksa any more info on this? As I said earlier, I don't see any explanation for the error you saw in the code you included, and your Django shell test seems to show it's working correctly.
Sorry, I still can't reproduce the issue :frowning_face: .
I'm guessing maybe you were running with an older version of django-anymail in the environment where the error occurred, and had some problem with your boto3 credentials. That would make this a duplicate of #308. (Or perhaps you were running with an older version of boto3 that didn't support SES v2, which could cause a similar error.)
If you see the problem again and can provide more info, please add it here and I'll reopen the issue.
We're using a custom email backend. Where
AnymailBackend
is amazon_sesEmailBackend
.Related issue with #308
I have tried to reproduce the issue by recreating the email backend from shell, but the client does have the require function