Home > Mobile >  AWS SES sending email from Django App fails
AWS SES sending email from Django App fails

Time:12-08

I am trying to send mail with using SES and already setup the mail configuration. Now SES running on production mode -not sandbox-. But in Django App, when I try to send mail nothing happens. it's only keep trying to send, no error.

in setting.py made the configuration.

INSTALLED_APPS = [
  'django_ses',
]

EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_SES_REGION_NAME = 'ap-northeast-1'
AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-northeast-1.amazonaws.com'

and email method.

def send_mail(request, user, emails, subject, path):
  current_site = get_current_site(request)
  message = render_to_string(f"store/emails/{path}.html", {
    "some": "context"
  })

  send_email = EmailMessage(subject, message, "[email protected]", to=emails)
  send_email.send()

By the way I already verified the [email protected] in SES console. And when I try to send email from the SES console using send test email option, I can send without a problem. But in Django App. I can't.

Is there any other settings should I do. Because I can't see any error popping when I try to send mail. It's only keep trying to send. But it can't.

CodePudding user response:

AWS SES provides two types of endpoints: API and SMTP

You are using SMTP one

AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-northeast-1.amazonaws.com'

But 'django_ses.SESBackend' working with API type.

Try to set:

EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_SES_REGION_ENDPOINT = 'email.ap-northeast-1.amazonaws.com'

If you want to use usual SMTP connection, you probably need to swap current backend with backends.smtp.EmailBackend and set SMTP connection parameters.

  • Related