Rahul
Rahul

Reputation: 13

Django PasswordResetView not Sending Email (Django 5, Gmail SMTP)

Problem: I'm facing an issue where the PasswordResetView in my Django project is not sending emails. I have tested my email configurations using the Django shell and a custom email route, and emails are sent successfully. However, the default PasswordResetView and the password reset page in the Django administration panel do not send emails.

Environment:

Email Settings (settings.py):

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("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")

DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER")
SERVER_EMAIL = os.environ.get("EMAIL_HOST_USER")

# Custom User Model
AUTH_USER_MODEL = "accounts.CustomUser"


Views and URLs:
I have tried using a custom view (custom_password_reset) and the default PasswordResetView, but both do not send emails.

    # views.py
    def custom_password_reset(request):
        return auth_views.PasswordResetView.as_view(
            template_name="accounts/password-reset.html",
            success_url=reverse_lazy("accounts:password-reset-done"),
            extra_email_context={"request": request},
        )(request)
    
    # urls.py
    path("password-reset/", views.custom_password_reset, name="password-reset"),


Additional Information:

    I have tested sending emails from the Django shell, and it works.
    I have allowed less-secure app access for my Gmail account.

I appreciate any insights or suggestions on resolving this issue. Thank you!

Upvotes: 1

Views: 74

Answers (0)

Related Questions