DJANGO SMTP错误发送电子邮件使用HTTPS(SSL) - 部署在AWS ElasticBeanstalk中

发布于 2025-02-02 22:21:35 字数 4961 浏览 4 评论 0原文

我正在发送一个帐户验证电子邮件,并且我正在利用AWS-EB部署它,在本地主机上它的功能,但是使用HTTPS,我会遇到一个错误(我只是配置了Gmail来允许其他应用程序,我不知道,我不知道t知道我是需要在ElasticBeanstalk还是在Gmail上设置配置)。

我必须在gmail中配置某些域名吗?

我在Gmail中所做的唯一配置是允许更不固定的应用程序,而我有一个恢复电子邮件和号码,但是我的步骤验证也已禁用,并且我的数字验证也是如此。

settings.py:views.py:STMP

if DEBUG:
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True
    EMAIL_HOST_USER = '[email protected]'
    EMAIL_HOST_PASSWORD = 'mypassword bla bla bla'  # important
else:
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

{% autoescape off %}
Hi {{ user.user_name }},

Sua conta foi registrada com
{%comment%}
http://{{ domain }}{% url 'account:activate' uidb64=uid token=token %}

{%endcomment%}
https:/{{ jamelaumn.com }}{% url 'account:activate' uidb64=uid token=token %}
{% endautoescape %}

中的

def account_register(request):

    if request.user.is_authenticated:
        return redirect('account:dashboard')

    if request.method == 'POST':
        registerForm = RegistrationForm(request.POST)
        if registerForm.is_valid():
            user = registerForm.save(commit=False)
            user.email = registerForm.cleaned_data['email']
            user.set_password(registerForm.cleaned_data['password'])
            user.is_active = False
            email_to = user.email
            user.save()
            email_subject = 'Ative sua conta'
            current_site = get_current_site(request)
            message = render_to_string('account/registration/account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
            html_message = "<br> oi </br>"

            email_body = message
            send_mail(subject=email_subject, message=email_body,
                      from_email=settings.EMAIL_HOST_USER, recipient_list=[
                          email_to],
                      html_message=html_message)

            email = EmailMessage(
                email_subject,
                email_body,
                settings.EMAIL_HOST_USER, [email_to])
            email.send()
            return HttpResponse('registered succesfully and activation sent')
    else:
        registerForm = RegistrationForm()
    return render(request, 'account/registration/register.html', {'form': registerForm})


def account_activate(request, uidb64, token):
    try:
        uid = urlsafe_base64_decode(uidb64)
        user = UserBase.objects.get(pk=uid)
    except(TypeError, ValueError, OverflowError, user.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        login(request, user)
        return redirect('account:dashboard')
    else:
        return render(request, 'account/registration/activation_invalid.html')

错误:

SMTPAuthenticationError at /django-store-account/register/
(534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu\n5.7.14 OabzR97ERR4QGxHg-aDM9dl1YuUtJS0-LbYjhx4ss7HxJE54i_0wzoKwaKI06jbZMi5pc\n5.7.14 _j_m6Gsoid9wDCvlNx1nSvCY157pl7nDPK6zF7cHkb8dya8-6V2KdTvpg0kbS42V>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 r2-20020a4ab502000000b0040e699e8d8asm4256417ooo.45 - gsmtp')





Request Method: POST
Request URL:    https://www.jamelaumn.com/django-store-account/register/
Django Version: 4.0.3
Exception Type: SMTPAuthenticationError
Exception Value:    
(534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu\n5.7.14 OabzR97ERR4QGxHg-aDM9dl1YuUtJS0-LbYjhx4ss7HxJE54i_0wzoKwaKI06jbZMi5pc\n5.7.14 _j_m6Gsoid9wDCvlNx1nSvCY157pl7nDPK6zF7cHkb8dya8-6V2KdTvpg0kbS42V>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 r2-20020a4ab502000000b0040e699e8d8asm4256417ooo.45 - gsmtp')
Exception Location: /usr/lib64/python3.8/smtplib.py, line 646, in auth
Python Executable:  /var/app/venv/staging-LQM1lest/bin/python
Python Version: 3.8.5
Python Path:    
['/var/app/current',
 '/var/app/venv/staging-LQM1lest/bin',
 '/var/app/venv/staging-LQM1lest/bin',
 '/usr/lib64/python38.zip',
 '/usr/lib64/python3.8',
 '/usr/lib64/python3.8/lib-dynload',
 '/var/app/venv/staging-LQM1lest/lib64/python3.8/site-packages',
 '/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages']
Server time:    Sun, 29 May 2022 20:29:04 -0300

I'm sending an account verification e-mail and I'm utilizing AWS-EB to deploy it, in local with localhost it's functioning, but with https I get an error(I just configured the gmail to allow other apps, I don't know if I need to set an configuration at ElasticBeanstalk or another at gmail).

Do I have to configure something in gmail for domains?

The only configuration I did in Gmail was to allow less secure apps nothing else, and I have an recuperation e-mail and number, but my to steps verification is disabled and my number verification too.

settings.py:

if DEBUG:
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True
    EMAIL_HOST_USER = '[email protected]'
    EMAIL_HOST_PASSWORD = 'mypassword bla bla bla'  # important
else:
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

{% autoescape off %}
Hi {{ user.user_name }},

Sua conta foi registrada com
{%comment%}
http://{{ domain }}{% url 'account:activate' uidb64=uid token=token %}

{%endcomment%}
https:/{{ jamelaumn.com }}{% url 'account:activate' uidb64=uid token=token %}
{% endautoescape %}

views.py:

def account_register(request):

    if request.user.is_authenticated:
        return redirect('account:dashboard')

    if request.method == 'POST':
        registerForm = RegistrationForm(request.POST)
        if registerForm.is_valid():
            user = registerForm.save(commit=False)
            user.email = registerForm.cleaned_data['email']
            user.set_password(registerForm.cleaned_data['password'])
            user.is_active = False
            email_to = user.email
            user.save()
            email_subject = 'Ative sua conta'
            current_site = get_current_site(request)
            message = render_to_string('account/registration/account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
            html_message = "<br> oi </br>"

            email_body = message
            send_mail(subject=email_subject, message=email_body,
                      from_email=settings.EMAIL_HOST_USER, recipient_list=[
                          email_to],
                      html_message=html_message)

            email = EmailMessage(
                email_subject,
                email_body,
                settings.EMAIL_HOST_USER, [email_to])
            email.send()
            return HttpResponse('registered succesfully and activation sent')
    else:
        registerForm = RegistrationForm()
    return render(request, 'account/registration/register.html', {'form': registerForm})


def account_activate(request, uidb64, token):
    try:
        uid = urlsafe_base64_decode(uidb64)
        user = UserBase.objects.get(pk=uid)
    except(TypeError, ValueError, OverflowError, user.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        login(request, user)
        return redirect('account:dashboard')
    else:
        return render(request, 'account/registration/activation_invalid.html')

Error in STMP:

SMTPAuthenticationError at /django-store-account/register/
(534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu\n5.7.14 OabzR97ERR4QGxHg-aDM9dl1YuUtJS0-LbYjhx4ss7HxJE54i_0wzoKwaKI06jbZMi5pc\n5.7.14 _j_m6Gsoid9wDCvlNx1nSvCY157pl7nDPK6zF7cHkb8dya8-6V2KdTvpg0kbS42V>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 r2-20020a4ab502000000b0040e699e8d8asm4256417ooo.45 - gsmtp')





Request Method: POST
Request URL:    https://www.jamelaumn.com/django-store-account/register/
Django Version: 4.0.3
Exception Type: SMTPAuthenticationError
Exception Value:    
(534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu\n5.7.14 OabzR97ERR4QGxHg-aDM9dl1YuUtJS0-LbYjhx4ss7HxJE54i_0wzoKwaKI06jbZMi5pc\n5.7.14 _j_m6Gsoid9wDCvlNx1nSvCY157pl7nDPK6zF7cHkb8dya8-6V2KdTvpg0kbS42V>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 r2-20020a4ab502000000b0040e699e8d8asm4256417ooo.45 - gsmtp')
Exception Location: /usr/lib64/python3.8/smtplib.py, line 646, in auth
Python Executable:  /var/app/venv/staging-LQM1lest/bin/python
Python Version: 3.8.5
Python Path:    
['/var/app/current',
 '/var/app/venv/staging-LQM1lest/bin',
 '/var/app/venv/staging-LQM1lest/bin',
 '/usr/lib64/python38.zip',
 '/usr/lib64/python3.8',
 '/usr/lib64/python3.8/lib-dynload',
 '/var/app/venv/staging-LQM1lest/lib64/python3.8/site-packages',
 '/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages']
Server time:    Sun, 29 May 2022 20:29:04 -0300

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文