سؤال

I am using django-ses to send e-mail using AWS Simple E-mail Service. I have no problem sending using send_mail() but from the same e-mail address set in settings, using mail_managers() I am getting a MessageRejected exception.

Here is a walk-through:

$ python manage.py ses_email_address -l
Fetching list of verified emails:
gez@gez.com

And via python shell:

>>> settings.DEFAULT_FROM_EMAIL
'gez@gez.com'
>>> settings.MANAGERS
(('omat', 'om@tekno.org'),)
>>> send_mail('test', 'test', 'gez@gez.com', ['om@tekno.org'])
1
>>> mail_managers('test', 'test')
BotoServerError: BotoServerError: 400 Bad Request
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
  <Error>
    <Type>Sender</Type>
    <Code>MessageRejected</Code>
    <Message>Email address is not verified.</Message>
  </Error>
  <RequestId>66269bb3-ca86-11e1-80db-5b89cf7a6356</RequestId>
</ErrorResponse>

Thanks for any help.

هل كانت مفيدة؟

المحلول

This isn't caused by django-ses. Both mail_admins and mail_managers use the SERVER_EMAIL setting as the From address not DEFAULT_FROM_EMAIL: https://docs.djangoproject.com/en/1.4/topics/email/#mail-managers

نصائح أخرى

I had some trouble getting error 500 emails raised in Amazon SES. This procedure may help others.

Things to check:

  • It works locally! (I used django.core.mail.backends.console.EmailBackend)

    • This means that you can generate an application error and you'll see it in the console of the running server
  • ADMINS needs to be defined

  • Check that there are no filters which prevent mails being sent when DEBUG=False

  • If it doesn't work locally, run a debugger and step through AdminEmailHandler. This might clear up why the email doesn't get sent.

If it all works locally, deploy to AWS.

  • Check that your application can send email (!), for example:

    • Fire an internal email such as reset password
    • Connect to the app via an EC2 instance and call send_email()
  • Login to the SES console and check that the email has been sent (under 'Sending statistics')

  • Trigger a 500 error - sending statistics should also increase, indicating that SES sent an email.

  • Is the email received?

    • Check spam folders
    • Is the target email address listed under 'Email addresses' in SES (necessary if your SES account is in the sandbox)
  • I had to ensure that DEFAULT_FROM_EMAIL and SERVER_EMAIL were set to email addresses listed as verified in SES

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top