Sending email to reset password in a blog app

Hello there,
I am making my first django project (a blog application) and I am almost finished but when I enter my email in password-reset view, it says that email has been sent without throwing any error but my gmail is not receiving any email and not even showing any error so that I can solve that.
The app is not showing any error while this is not working :disappointed:
Someone help :pray:

First, I would verify that you’ve got Django set up correctly to send any email. Once you’ve verified that you’ve got all the settings correct (see all the settings starting with EMAIL_), try sending an email manually using the Quick example in the Django shell.

If that doesn’t come through, there might be a reason why gmail is rejecting your emails. See if you can test with someone else on a different email domain.

1 Like

This is setting.py of my project
please to meet you sir!

Please do not post screenshots here. They’re difficult to read and impossible to quote. Copy/paste the relevant lines of text.

When you post code snippets, please insert them between lines containing only 3 backticks - ```. (Make sure you use the backtick - ` and not the apostrophe - '.) That means you would have one line with the 3 backticks, your code, and then one more line with just the 3 backticks. That allows this forum software to format your code nicely:

# The line above this is just ```
def function(parm):
    return parm
# The line after this is just ```
1 Like
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('User_Email')
EMAIL_HOST_PASSWORD = os.environ.get('User_Password')

Have you tried sending the sample email manually through the shell? If so, what was the result?

1 Like

I have not tried that yet,thought you would check my settings first and if there is/are any problem in that
i would fix that first as you told me

I have just done that,
got SMTPAuthenticationError

Ok, what do you think that message is telling you?

hello sir,
I apologize for late reply due to some personal reasons.
Sir I have tried sending mail form my Gmail to my own Gmail but first failed.
So I went to my Gmail and turned on less secure app settings and now I can send email manually.
Please guide me on how may I send Email to my users so that they can reset their account’s password in my app.

If you can now send the email manually through the shell, your app should work.

I am afraid,but it is not working please help!

Is my setting alright? in setting.py?

urlpatterns = [
    path('admin/', admin.site.urls),
    path("register/", user_views.register, name="register"),
    path("profile/", user_views.profile, name="profile"),
    path("login/",auth_views.LoginView.as_view(template_name='users/login.html'), name="login"),
    path("logout/",auth_views.LogoutView.as_view(template_name='users/logout.html'), name="logout"),
    path("password-reset/",auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'), name="password_reset"),
    path("password-reset/done/",auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'),
         name="password_reset_done"),
    path("password-reset-confirm/<uidb64>/<token>/",auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'),
         name="password_reset_confirm"),
    path('', include("blog.urls"))
]

Those are the same settings as when you did it manually, right? If so, then that’s a sign that your settings are correct.

Two things to check -

  • Are you using the system standard password reset view, or a custom view you’ve written? If the latter, then it might be worth posting your view, form, and template associated with that view.
  • Is the email address you’re testing a valid email address for a user in the system? Django won’t send an email to an address not associated with a user.

I am using custom view I have written
You wish to see the view form and templates?
Yes that is a valid email address
actually for now I am trying to send email to my own address but later I shall change that if needed


This is what’s happening with me in practice!
my app is not sending email but also not throwing any error just showing email has been sent but in reality no email is sent.
According to documentation, It is because email is not registered in the system but You saw my seetings.py I have registered EMAIL_HOST_USER and also EMAIL_HOST_PASSWORD and everything needed

That’s not what it’s referring to.

Your email address has to be a User within your Django application. It’s got nothing to do with the settings.