I am trying to send email from django
with django-ses
library but getting error:
boto.exception.BotoServerError: BotoServerError: 403 Forbidden
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>
</Error>
<RequestId>7e2103e0-729f-11a9-aq25-51a2dqa8ae97</RequestId>
</ErrorResponse>
I verified the domain and verified admin address [email protected]
address in AWS console and created API key and secret from the SES dashboard.
Django settings:
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_SES_ACCESS_KEY_ID = os.environ.get('AWS_SES_ACCESS_KEY_ID')
AWS_SES_SECRET_ACCESS_KEY = os.environ.get('AWS_SES_SECRET_ACCESS_KEY')
AWS_SES_REGION_NAME = 'eu-west-1' # because I use ireland server, but same error without this
SERVER_EMAIL = '[email protected]'
DEFAULT_FROM_EMAIL = '"Hello You" <[email protected]>'
and I try to send email with:
from django.core.mail import EmailMessage
from django.conf import settings
email = EmailMessage(
'Hello',
'World',
settings.DEFAULT_FROM_EMAIL,
to=['[email protected]']
)
email.send()
What can be a problem here?
You're making Call by API (sendemail or sendrawemail) not SMTP.
AWS_SES_ACCESS_KEY_ID = os.environ.get('AWS_SES_ACCESS_KEY_ID') AWS_SES_SECRET_ACCESS_KEY = os.environ.get('AWS_SES_SECRET_ACCESS_KEY')
The Access key and secret key here should be IAM user keys who has access to SES. To make an sendemail or sendrawemail Call, you need to use/create an IAM user from the IAM console and use those credentials, make sure the user has a policy allows access to SES.
If you get the keys from SES console , these only work for SMTP.
SMTP and general IAM credentials are different but you can convert them , refer below link:
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html