0

I have been struggling to solve this for the last 3 hours but couldn't find it. My problem is that Django is not sending email and even if I enter the wrong username and password it shows successful .It never sends mail. Please tell me what I am doing wrong.Here is my settings.py file

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

My urls.py file: path('reset_password_complete',auth_views.PasswordResetCompleteView.as_view(),name='password_reset_complete'), path('reset/<uidb64>/<token>/',auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'), path('reset_password_sent/',auth_views.PasswordResetDoneView.as_view(),name='password_reset_done'), path('reset_password/',auth_views.PasswordResetView.as_view(),name="reset_password"),

I am using the default view of Django but even if my password is wrong or username is wrong it shows me email has been sent but it has not.Please help me.

  • And i have also allowed 'allow less secure apps' on my account – django try try Feb 02 '21 at 07:10
  • but it still doesn't work – django try try Feb 02 '21 at 07:10
  • It seems to me there is a problem in my settings.py file as even if I don't put these lines EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = '******************' EMAIL_HOST_PASSWORD = '********' It works as usual – django try try Feb 02 '21 at 07:23

1 Answers1

0

Make sure you have followed the instructions mentioned in the following two answers:

Django sending email with google SMTP

Sending emails on Django using SMTP and Gmail

If you are still facing problems and you're on a tight timeline, I would recommend using SendGrid's free plan and then add this to your settings.py file:

# settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
SENDGRID_API_KEY = 'YourAPIKey'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = 'YourHostPassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'example@mai.com' # the email that you used on SendGrid
Hofmann
  • 118
  • 1
  • 8
  • Thank u so much for the fast reply.I was just observing that my seetings.py isn't detecting what I wrote in it.Is there something I am doing wrong.Here is all the cde that I have entered in my settings.py till now. STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR,'media') MEDIA_URL = '/media/' CRISPY_TEMPLATE_PACK = 'bootstrap4' LOGIN_REDIRECT_URL = 'blog-home' LOGIN_URL = 'login' EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = '********' EMAIL_HOST_PASSWORD = '*******' – django try try Feb 02 '21 at 07:41
  • is it something that i have wirite first or or something like that.I am relatively new to django.But I will surely try your way – django try try Feb 02 '21 at 07:42
  • I just want to say whether I add those line to not my app is still working the same – django try try Feb 02 '21 at 07:43
  • Are you using [django-allauth](https://django-allauth.readthedocs.io/en/latest/installation.html)? – Hofmann Feb 02 '21 at 07:54
  • No , i am using django 3.1.4 – django try try Feb 02 '21 at 08:00
  • I would recommend adding [django-allauth](https://django-allauth.readthedocs.io/en/latest/overview.html) to your project and doing more research on authentication in Django. – Hofmann Feb 02 '21 at 08:04