My settings.py
:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = '*******'
DEFAULT_FROM_EMAIL = '[email protected]
But a mail is not sent to the address, in the console the print.html
is printing when I click on send_email
, but it's not sending any email.
I am using Django 1.3.7 and Python 2.6.
I don't know the problem is with the version or some logic problem.
First we need to configure the email host server in the settings.py for confirmation mail. Add the below configuration in the settings.py file. We used the email-id along with the password and gmail SMTP host server. You can use the other SMTP server as well.
Inside of the “send_mail.py”, create a function that takes in the following arguments. def send_mail(html,text='Email_body',subject='Hello word',from_email='',to_emails=[]): The next step would be to make sure that the “to_emails” argument is always a “list of emails” and not a string or any other data type.
In settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
console.EmailBackend
will print the mail in the console. So using
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
solved my problem. It is already documented here: Django docs: Email
I personally just switched to my production server when this happened. Because this is a new IP location, Google attempted to protect my account by blocking the sign-in.
To fix this, I followed the steps in this answer:
First, enable access to less secure apps in your Google account here: https://www.google.com/settings/security/lesssecureapps
Since I had already done this, and my problem was now because of a new IP address, I had to manually confirm the next sign-in attempt using this link: https://accounts.google.com/DisplayUnlockCaptcha
See the linked answer for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With