0

I am unable to use django's default password_reset. It isn't sending emails. I have tried many many configurations but nothing is working.

I know my settings are right, As I am fully able to send emails in views.py Following Code is absolutely working.

from django.core.mail import send_mail

def contact_us(request):
    contact_form = ContactForm(request.POST or None)
    context = {
        "form": contact_form,
    }
    if contact_form.is_valid():
        print(contact_form.cleaned_data)
        send_mail(
            'Contacted By: {}'.format(contact_form.cleaned_data.get('name')),
            contact_form.cleaned_data.get('comment'),
            'mydjangoemail@gmail.com',
            ['customerfeedback@gmail.com',],
            fail_silently=False,
        )
    if request.is_ajax():
        return JsonResponse({"message": "Thanks"})

if contact_form.errors:
    errors = contact_form.errors.as_json()
    if request.is_ajax():
    
        return HttpResponse(errors, status=400, content_type='application/json')
return redirect("App:home")

My above is working but I don't what is wrong with following code that password_reset not sending emails

I am using django's default password_reset by using following in project's urls.py, I am accessing all templates like password_reset at http://127.0.0.1:8000/accounts/password_reset/:

path('accounts/', include('django.contrib.auth.urls')),

templates are working fine too:

password_reset

my settings.py has following email config:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'mydjangoemail@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 25
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'mydjangoemail@gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

MANAGERS = (
    ('Abc', "mydjangoemail@gmail.com"),
)

ADMINS = MANAGERS

And 'django.contrib.auth' is also in INSTALLED_APPS.

Newbie
  • 53
  • 6
  • Show us what is not working.... You are showing what is working – Biplove Lamichhane Aug 08 '20 at 02:37
  • @Biplove `password_reset` is not working at all. I enter email and hit submit, I get the `done view` but email is not sending. – Newbie Aug 08 '20 at 02:42
  • 1
    Does an active user with the entered email exist in your DB? – Iain Shelvington Aug 08 '20 at 02:48
  • @IainShelvington Amazing dear sir. I didn't know at all it should be there. Thank you so much. Can you point out where in docs its theory explained ? – Newbie Aug 08 '20 at 02:59
  • 1
    @NanoByte https://docs.djangoproject.com/en/3.0/topics/auth/default/#django.contrib.auth.views.PasswordResetView `If the email address provided does not exist in the system, this view won’t send an email, but the user won’t receive any error message either ` – Iain Shelvington Aug 08 '20 at 03:02

0 Answers0