Question
Asked By – Derek
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?
Now we will see solution for issue: How to send email via Django?
Answer
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.
This question is answered By – Ignacio Vazquez-Abrams
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0