Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smpt django on production server

Tags:

django

I deploy my django project and my contact form stoped work. I tried some tips find on stack, but it doesn't works, help me plz.

Here my local settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'

and my view:

def contact_form(request):

    form = ContactForm(request.POST or None)    
    if form.is_valid():
        message = form.cleaned_data.get('message')
        email = form.cleaned_data.get('email') 
        subject = 'contact form'
        from_email = email
        to_email = (settings.EMAIL_HOST_USER,)
        contact_message = '%s, from %s' %(message, from_email)

        send_mail(subject, contact_message, from_email, to_email, fail_silently=False)
        form = ContactForm()
        request.session.set_expiry(10)
        request.session['pause'] = True

    return render(request, 'contact_form.html', {'form':form})

Now when I send message I have "Internal Server Error".

like image 833
Ivan Semochkin Avatar asked Oct 19 '22 19:10

Ivan Semochkin


1 Answers

I contacted Baterson via Skype and solved this issue together. the production server didnot support smtp settings and there were some other bugs. So we fixed them all and finally decided to just use:

EMAIL_HOST = 'localhost'
EMAIL_PORT = 25

all is working now

like image 131
doniyor Avatar answered Oct 21 '22 15:10

doniyor