A
A
alexkomp2019-07-27 13:01:41
Django
alexkomp, 2019-07-27 13:01:41

Why is email not being sent to confirm email in django?

I'm trying to make a user registration with email confirmation by mail.
But when sending email it gives error "[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1045)"
EMAIL_HOST = 'smtp.mail.ru'
EMAIL_PORT = 2525
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = "** *******"
EMAIL_USE_SSL = True
views.py

def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string('acc_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 = form.cleaned_data.get('email')
            email = EmailMessage(
                        mail_subject, message, to=[to_email]
            )
            email.send()
            return HttpResponse('Please confirm your email address to complete the registration')
    else:
        form = SignupForm()
    return render(request, 'signup.html', {'form': form})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexkomp, 2019-07-27
@alexkomp

It's better to do it through gmail. Got it through gmail.
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = "your_password"
EMAIL_USE_TLS = True

N
Netupovy, 2021-04-30
@Netupovy

There is a solution on stackoverflow .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question