使用SES在AWS中为Django设置电子邮件

时间:2018-02-01 23:09:54

标签: django amazon-web-services email elastic-beanstalk django-allauth

我正在尝试使用Elastic Beanstalk在AWS上为我的Django网站设置电子邮件功能。我已激活简单电子邮件服务(SES)并验证了两个电子邮件地址以进行测试。此外,我已按照说明安装和设置Dango-SES。但是,当我尝试在我的网站上注册假冒新用户时,我在浏览器中收到此错误(Traceback):

    Environment:


Django Version: 1.9
Python Version: 2.7.12
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'crispy_forms',
 'newsletter',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'ajaxuploader')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.models.Session')



Traceback:

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/opt/python/current/app/allauth/account/views.py" in dispatch
  210.         return super(SignupView, self).dispatch(request, *args, **kwargs)

File "/opt/python/current/app/allauth/account/views.py" in dispatch
  79.                                             **kwargs)

File "/opt/python/current/app/allauth/account/views.py" in dispatch
  188.                                                           **kwargs)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/opt/python/current/app/allauth/account/views.py" in post
  102.             response = self.form_valid(form)

File "/opt/python/current/app/allauth/account/views.py" in form_valid
  231.                 self.get_success_url())

File "/opt/python/current/app/allauth/account/utils.py" in complete_signup
  188.                          signal_kwargs=signal_kwargs)

File "/opt/python/current/app/allauth/account/utils.py" in perform_login
  148.             send_email_confirmation(request, user, signup=signup)

File "/opt/python/current/app/allauth/account/utils.py" in send_email_confirmation
  319.                                                     signup=signup)

File "/opt/python/current/app/allauth/account/models.py" in send_confirmation
  60.         confirmation.send(request, signup=signup)

File "/opt/python/current/app/allauth/account/models.py" in send
  166.         get_adapter(request).send_confirmation_mail(request, self, signup)

File "/opt/python/current/app/allauth/account/adapter.py" in send_confirmation_mail
  447.                        ctx)

File "/opt/python/current/app/allauth/account/adapter.py" in send_mail
  140.         msg.send()

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/mail/message.py" in send
  292.         return self.get_connection(fail_silently).send_messages([self])

File "/opt/python/run/venv/local/lib/python2.7/site-packages/django_ses/__init__.py" in send_messages
  200.                                           dkim_headers=self.dkim_headers)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/boto/ses/connection.py" in send_raw_email
  323.         return self._make_request('SendRawEmail', params)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/boto/ses/connection.py" in _make_request
  119.             self._handle_error(response, body)

File "/opt/python/run/venv/local/lib/python2.7/site-packages/boto/ses/connection.py" in _handle_error
  177.         raise ExceptionToRaise(response.status, exc_reason, body)

Exception Type: SESAddressNotVerifiedError at /accounts/signup/
Exception Value: SESAddressNotVerifiedError: 400 Email address is not verified.
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
  <Error>
    <Type>Sender</Type>
    <Code>MessageRejected</Code>
    <Message>Email address is not verified. The following identities failed the check in region US-WEST-2: webmaster@localhost</Message>
  </Error>
  <RequestId>e89fc6ee-07aa-11e8-ad7d-79b7437444ea</RequestId>
</ErrorResponse>

这令人困惑,因为我使用经过验证的电子邮件进行注册(由SES验证的电子邮件)。我正在使用django-allauth进行身份验证和注册。 这是我的Django设置:

AUTHENTICATION_BACKENDS = (

    'django.contrib.auth.backends.ModelBackend',

    'allauth.account.auth_backends.AuthenticationBackend',
)

SITE_ID = 1

EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = 'My Key'
AWS_SECRET_ACCESS_KEY = 'My Key'

AWS_SES_REGION_NAME = 'us-west-2'
AWS_SES_REGION_ENDPOINT = 'email.us-west-2.amazonaws.com'

有人可以就此提出建议吗?

非常感谢!

此致

1 个答案:

答案 0 :(得分:1)

您的观点是尝试发送电子邮件,并使用DEFAULT_FROM_EMAIL作为发件人地址。

您尚未设置DEFAULT_FROM_EMAIL,因此默认为webmaster@ localhost。 Amazon SES会给您一个错误,因为您尚未验证此地址。

您可以通过将DEFAULT_FROM_EMAIL设置为已通过SES验证的地址来解决问题。