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=['email@example.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 firstname.lastname@example.org?
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 and
EmailMessage.send() is used instead?
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.
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.
EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = 'email@example.com' EMAIL_HOST_PASSWORD = 'password'
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