Not able to send email - Django
Asked Answered
S

2

23

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.

Specialistic answered 11/6, 2013 at 10:26 Comment(9)
Have you turned on debugging? DEBUG = True in settings.py? Then, can u for example send email using your other local mail clients? Are you certain about your local smtp settings being fine? Are there any errors in the system mail or http logs?Raviv
what's your email config in settings.py?Statutable
@nemesisfixx DEBUG = TRUE in settings.py,how to check the latter oneSpecialistic
@SamueleMattiuzzo settings.py updatedSpecialistic
@Specialistic on which OS are u testing this? If it's a *nix box, try testing that u can actually send email using the mail command for example. Otherwise, another thing to check is to see whether the ajax request even hits the server... ;-/Raviv
@nemesisfixx using fedora 14(Linux)Specialistic
All,in console i am getting the template,on send_mailSpecialistic
@nemesisfixx Ajax is returning the success message,but mail not sendSpecialistic
Fire up a manage.py shell and try to send mail from there.Mashburn
S
44

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

Specialistic answered 12/6, 2013 at 8:14 Comment(2)
This little change makes every natural way to proceed the good way to proceed. With everything right in except of this line, it worked always without error but the email wasn't sent. Now there are no errors and the email is sent (: .Coleoptile
Thank you. #Added this to exceed the min. number of words for commentFreckle
H
1

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.

Hilly answered 19/10, 2020 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.