0
votes

I have a web using Django framework run in localhost, I want web send email automatically to a email address, but I have a trouble in config EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD and EMAIL_PORT in settings.py

this is settings.py I configured:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST = 'localhost'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 25

How can I fix to send email?

1

1 Answers

0
votes

Your project runs on localhost but your mailserver runs on google

try this

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD

You will need to set up Gmail, say with an application password. See the google guide here and for app passwords here

If you connect using SSL or TLS, you can send mail to anyone with smtp.gmail.com.

Note: Before you start the configuration, we recommend you set up App passwords for the the desired account. Learn more at Sign in using App Passwords and Manage a user's security settings.

Connect to smtp.gmail.com on port 465, if you’re using SSL. (Connect on port 587 if you’re using TLS.) Sign in with a Google username and password for authentication to connect with SSL or TLS. Ensure that the username you use has cleared the CAPTCHA word verification test that appears when you first sign in.

But if you are using gmail then you should look into the gmail api because then you can deal with inbound mails and you can use labels etc to manage the mails, it works well eventually once you get your head around oAuth etc. I know you didn't ask about that, but I personally find it useful.