This is a password reset link system that uses Django’s auth views. My SMTP configuration works fine and testing with send_mail
in the Django shell shows a success and I get the test email, however when Django tries to carry out the password reset process itself, no email is actually sent.
Urls.py:
path("reset_password/", auth_views.PasswordResetView.as_view(), name="reset_password"), # Password reset submition page
path("reset_password_sent/", auth_views.PasswordResetDoneView.as_view(), name="password_reset_done"), # renders success email sent message
path("reset/<uidb64>/<token>/", auth_views.PasswordResetConfirmView.as_view(), name="password_reset_confirm"), # The link the user receives
path("reset_password_complete/", auth_views.PasswordResetCompleteView.as_view(), name="password_reset_complete"), # Succesful password reset
Settings.py:
#SMTP Configuration
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST_USER = "<name>@gmail.com"
EMAIL_HOST_PASSWORD = "<app password>"
Already tried the following:
- Tried using app passwords instead of normal.
- Different email provider (outlook)
No success thus far, and I’m unsure of the cause of the problem. All help is appreciated thanks.
Are you testing this from the server where you have this installed?
What do your logs show for the requests being made to run the password reset views?
You might want to change your logging to log more data during this process.
Yes, its a local environment.
[03/Dec/2024 23:27:10] "POST /reset_password/ HTTP/1.1" 302 0
[03/Dec/2024 23:27:10] "GET /reset_password_sent/ HTTP/1.1" 200 3625
No errors, the HTTP requests are OK.
This error was reoccurring in the verbose output of the POST request made:
type object 'RequestContext' has no attribute 'site_title'
This chains onto other missing attributes in RequestContext
like is_popup
, is_nav_sidebar_enabled
and has_permission
.
I think I might just try to create a custom template & view to mitigate these RequestContext errors and see if it resolves itself, as the default seems buggy.
The other thing to check is that the email address for the account you’re trying to reset is a valid account for having its password reset through this process.
I opted not to use Django’s built-in’s for my user authentication and did it from-scratch, so would that prove a problem as to why the account may not be seen as “valid”?
It’s possible, but without all the details it’s going to be hard to tell.
On success the registration does:
form = RegisterForm(request.POST)
new_user = form.save(commit=False)
new_user.save()
Which does create a user because it wont allow another account with the same email. How is an account determined for validity?
See the docs at PasswordResetView for the list of conditions required for the email to be sent.