Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to send email - Django

Tags:

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.

like image 444
user2086641 Avatar asked Jun 11 '13 10:06

user2086641


People also ask

How does Django verify email?

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.

How do I send an email notification in Django REST framework?

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.


2 Answers

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

like image 165
user2086641 Avatar answered Sep 19 '22 09:09

user2086641


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.

like image 36
user-124812948 Avatar answered Sep 19 '22 09:09

user-124812948