Reputation: 984
Working on a contact form and i am not able to receive the emails from Django into my Inbox.
This is my function:
def contact(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
contact_name = form.cleaned_data['contact_name']
contact_phone = form.cleaned_data['contact_phone']
contact_period = form.cleaned_data['contact_period']
subject = contact_name + " | " + contact_phone + " | " + contact_period
content = form.cleaned_data['content']
contact_email = form.cleaned_data['contact_email']
try:
send_mail(subject,content,contact_email, ['[email protected]'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('success')
return render(request, "contact.html", {'form': form})
def success(request):
return HttpResponse('Success! Thank you for your message.')
These are my server's settings:
Secure SSL/TLS Settings (Recommended)
Username: [email protected]
Password: Use the email account’s password.
Incoming Server: mail.cohen.ro
IMAP Port: 993 POP3 Port: 995
Outgoing Server: mail.cohen.ro
SMTP Port: 465
This is what i have in my Django settings: LATEREDIT: I have commented the console and have now this line of code, but doesnt submit the email.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_HOST= 'mail.cohen.ro'
EMAIL_HOST_USER= '[email protected]'
EMAIl_HOST_PASSWORD='mypass'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
In my server i can see the message, but does not send the email to my email address so i dont know if someone is asking me something. Thank you!
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: me | 0787877 | 12-13
From: [email protected]
To: [email protected]
Date: Mon, 25 Dec 2017 11:29:39 -0000
Message-ID: <[email protected]>
me
The error i got:
SMTPServerDisconnected at /contact/
Connection unexpectedly closed
Request Method: POST
Request URL: http://127.0.0.1:8000/contact/
Django Version: 2.0
Exception Type: SMTPServerDisconnected
Exception Value:
Connection unexpectedly closed
Exception Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py in getreply, line 393
Python Executable: /Users/cohen/PycharmProjects/chn/venv/bin/python
Python Version: 3.6.1
Python Path:
['/Users/cohen/PycharmProjects/chn',
'/Users/cohen/PycharmProjects/chn',
'/Users/cohen/PycharmProjects/static_in_env',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
'/Users/cohen/PycharmProjects/chn/venv/lib/python3.6/site-packages',
'/Users/cohen/PycharmProjects/chn/venv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg',
'/Users/cohen/PycharmProjects/chn/venv/lib/python3.6/site-packages/pip-9.0.1-py3.6.egg',
'/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend']
Server time: Mon, 25 Dec 2017 13:49:16 +0200
Any help, would be much appreciated!
Upvotes: 0
Views: 216
Reputation: 984
So, the issue was due to the fact that TLS was true and needed to be False ----EMAIL_USE_TLS = False
Now is submitting emails.
Upvotes: 1