I've recently set up a Django 1.7.3 website on my Ubuntu 12.04 server using Apache and mod_wsgi. Everythink works fine except the mail sending. I don't understand why this does not work since I've been using the same configuration (port, host etc.) on a previous PHP website and that worked. So it must be something coming from Python. The code and email sending also worked locally.
In my settings.py
file I have written my SMTP Hosting configuration :
EMAIL_HOST = 'SSL0.OVH.NET'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'contact@mywebsite.com'
EMAIL_HOST_PASSWORD = 'mypassword'
And here is my Contact function :
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
sender = form.cleaned_data['sender']
recipients = ['contact@mywebsite.com']
try:
send_mail(subject,message,sender, recipients)
return redirect('myapp:index')
except BadHeaderError:
return HttpResponse('Invalid header found.')
else:
form = ContactForm()
return render(request, 'myapp/form.html', {'form': form})
( I get the same error with send_mail('hello','a simple text message', 'me@gmail.com', ['contact@mywebsite.com'])
)
My error message:
SMTPDataError at /contact/
(554, b'mail server permanently rejected message (#5.3.0)')
Request Method: POST
Request URL: http://mywebsite.com/contact/
Django Version: 1.7
Exception Type: SMTPDataError
Exception Value: (554, b'mail server permanently rejected message (#5.3.0)')
Exception Location: /usr/lib/python3.2/smtplib.py in sendmail, line 761
Python Executable: /usr/bin/python
Python Version:3.2.3
Python Path:
['/opt/.virtualenvs/my_env/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg',
'/opt/.virtualenvs/my_env/lib/python3.2/site-packages/pip-1.1-py3.2.egg',
'/var/www/mywebsite',
'/opt/.virtualenvs/my_env/lib/python3.2/site-packages',
'/usr/lib/python3.2',
'/usr/lib/python3.2/plat-linux2',
'/usr/lib/python3.2/lib-dynload',
'/usr/local/lib/python3.2/dist-packages',
'/usr/lib/python3/dist-packages']
Thanks a lot for the help !
UPDATE I've got successful results using gmail as a smtp server, so the problem is coming from OVH ? (but it is strange because with the same settings for the same OVH mail account, I have no problem with the PHP website on the same server). I've contacted them and will keep you updated.
Hey I was just google with some part of your error and got this please check out:
and also check this:
https://productforums.google.com/forum/#!topic/gmail/hM8C1wJXGCo
maybe this helps you.
I recommend checking your hosts configuration for SMTP to ensure it isn't rejecting emails sent without a sender's address. If it is, you'll need to specify the sender in your settings.py
or your function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.