In my settings.py
, I have the following:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
My email code:
from django.core.mail import EmailMessage
email = EmailMessage('Hello', 'World', to=['user@gmail.com'])
email.send()
Of course, if I setup a debugging server via python -m smtpd -n -c DebuggingServer localhost:1025
, I can see the email in my terminal.
However, how do I actually send the email not to the debugging server but to user@gmail.com?
After reading your answers, let me get something straight:
Can't you use localhost(simple ubuntu pc) to send e-mails?
I thought in django 1.3
send_mail()
is somewhat deprecated andEmailMessage.send()
is used instead?
You need to use smtp as backend in settings.py
If you use backend as console, you will receive output in console
And also below settings in addition
If you are using gmail for this, setup 2-step verification and Application specific password and copy and paste that password in above EMAIL_HOST_PASSWORD value.
I use Gmail as my SMTP server for Django. Much easier than dealing with postfix or whatever other server. I'm not in the business of managing email servers.
In settings.py:
NOTE: In 2016 Gmail is not allowing this anymore by default. You can either use an external service like Sendgrid, or you can follow this tutorial from Google to reduce security but allow this option: https://support.google.com/accounts/answer/6010255
I had actually done this from Django a while back. Open up a legitimate GMail account & enter the credentials here. Here's my code -
My site is hosted on Godaddy and I have private email registered on the same. These are the settings which worked for me:
In settings.py:
In shell:
Then I got "1" as the O/P i.e. Success. And I recieved the mail too. :)
Send the email to a real SMTP server. If you don't want to set up your own then you can find companies that will run one for you, such as Google themselves.
For Django version 1.7, if above solutions dont work then try the following
in settings.py add
The last line did the trick for django 1.7