5👍
You haven’t configured all the email settings, if you are just testing the messages you can use the Console backend instead and send the email to standard output. Try overriding the default EMAIL_BACKEND
in you settings.py
:
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
If you are planning on sending emails with the default backend, you don’t need to import smtplib
, for that Django provides helper functions inside django.core.mail
:
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'from@example.com',
['to@example.com'], fail_silently=False)
Although, like I said before, you need to configure some things before hand. Take a look at the SMTP backend for more information.
Example settings:
# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'example@gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_SUBJECT_PREFIX = '[Test mail]'
0👍
If you are on a host with WHM enabled, like say Media Temple, i will save you some cursing, hair, etc.
There is a system level SMTP restriction configuration on these machines. Go in to WHM and find it and disable it. Like magic your SMTP works.
When the SMTP restriction is enabled, you will get 535 auth errors.
- [Django]-Error when sending email through Sendgrid API
- [Django]-Is there a default file upload size limit in django?