1

我正在尝试this library将我的 Django 项目与 AWS SES 集成。

设置.py

EMAIL_BACKEND = 'django_ses.SESBackend'

AWS_ACCESS_KEY_ID = 'my_aws_access_key'
AWS_SECRET_ACCESS_KEY = 'my_aws_secret_access_key'

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

它抛出以下错误

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: jpark1320@gmail.com, webmaster@localhost</Message>
  </Error>
  <RequestId>0220c0a0-741b-11e8-a153-475b5dfc6545</RequestId>
</ErrorResponse>

我什至无法猜测为什么我的代码有问题。但是,有一个问题可能是send_mail(). 我正在尝试向用户发送电子邮件以进行注册确认。我把发送电子邮件的代码放在下面。

SMTP 设置

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'my_google_email@gmail.com'
EMAIL_HOST_PASSWORD = 'my_google_email_password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'My Team Name <noreply@gmail.com>'

更新

视图.py

def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            # Create a user object to set email to be username before passing it to db
            user = form.save(commit=False)

            user.is_active = False
            user.email = form.cleaned_data['username']
            user.save()

            current_site = get_current_site(request)
            mail_subject = "[Modvisor] Please verify your email address."
            message = render_to_string('accounts/account_active_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
            to_email = user.email
            email = EmailMessage(
                        mail_subject, message, to=[to_email]
            )
            email.send()

            return redirect('signup_confirm')

    else:
        form = SignupForm()
    return render(request, 'accounts/register.html', {'form': form})
4

1 回答 1

4

错误的相关部分是“电子邮件地址未验证”。默认情况下,SES 处于沙盒模式,不允许您使用之前未验证的 From 或 To 地址。您需要在 SES 控制台中验证地址或打开支持请求以离开沙箱。

在 Amazon SES 中验证电子邮件地址

要验证地址,请转到 SES 控制台。在左侧选择电子邮件地址,然后单击验证新电子邮件地址。您将需要访问该电子邮件地址,以便您可以单击将发送到该地址的链接。

离开 Amazon SES 沙盒

要退出沙盒,只需打开支持请求,描述您的用例并等待几天。

于 2018-06-20T17:12:59.823 回答