Forums

Can't use cpanel mail in django

Trying to use a cpanel mail on my django app, i keep getting connection timed out. It works when i send mail from shell but doesn't from my views.

This is my settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = cpanel mail
EMAIL_HOST_USER = username
EMAIL_HOST_PASSWORD = password
EMAIL_PORT=587
EMAIL_USE_TLS=True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

This is my view:

def sendEmail(request):
form = SendEmail()
if request.method == "POST":
    form = SendEmail(request.POST)
    if form.is_valid():
        email = form.cleaned_data.get('email')
        subject = form.cleaned_data.get('subject')
        message = form.cleaned_data.get('message')
        send_mail(subject, message, EMAIL_HOST_USER, [email], fail_silently=False)
    return redirect('done')
context = {'form': form}
return render(request, 'send/email.html', context)

What do i do? P.S I am a paid user.

That sounds like the SMTP host that you're trying to connect to may be blocking the connection from the web server. This could be because of something you did that made them block it or it may just be that the IP was previously used by spammers or something. You can contact the admins of the machine to find out.