Django and AWS Simple Email Service

2020-07-27 03:23发布

问题:

I'm attempting to get a django site up and running and I'm trying to enable django's standard password reset service.

My site is hosted by AWS EC2, so I figured I would use AWS SES for my email service. However, I can't get the smtp connection to work. Any idea on how to solve for the following error:

Exception Type: SMTPSenderRefused Exception Value: (530, b'Authentication required', 'example@example.com')

I've looked at the following, but I'd prefer to stay with django's built-in email back-ends if possible:

  • https://github.com/django-ses/django-ses
  • https://github.com/azavea/django-amazon-ses
  • Amazon SES SMTP with Django

Email Settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'email-smtp.us-west-2.amazonaws.com'
EMAIL_PORT = 587 # (I've also tried 25, 465, & 2587)
EMAIL_HOST_USER = ''
EMAIL_PASSWORD = ''
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'example@example.com' # but my real email address

My EMAIL_HOST_USER and EMAIL_PASSWORD are set to my SMTP credentials I obtained by following the instructions at: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html

Also, I was sure to verify my DEFAULT_FROM_EMAIL and my domain following these instructions: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-addresses-and-domains.html

And DKIM is enabled and my nameservers have been updated.

Any help would really be appreciated.

UPDATE:

I was able to get the django email send working with the django-ses 3rd party library, but I'm still not able to figure out why the standard backend doesn't work via SMTP.

I think there is definitely something wrong with my code as I went so far as to switch email clients from AWS SES to Zoho mail and I'm still receiving the same 530 Authentication required error.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'support@example.com'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'support@example.com'
EMAIL_PASSWORD = ''

回答1:

If it is asking for Authentication, please double-check the following:

  • Your SMTP settings
  • The email that you're trying to send mails from belongs to the verified domain. e.g. if you have verified example.com but you try sending emails from something@gmail.com, it is going to ask for gmail auth credentials.