dj-rest-auth icon indicating copy to clipboard operation
dj-rest-auth copied to clipboard

Password reset HTML email not sending

Open anuj9196 opened this issue 3 years ago • 4 comments

Using custom serializer to pass HTML template name as the context

class CustomPasswordResetSerializer(PasswordResetSerializer):
    def get_email_options(self):
        return {
            'subject_template_name': 'account/email/password_reset_key_subject.txt',
            'email_template_name': 'account/email/password_reset_key_message.txt',
            'html_email_template_name': 'account/email/password_reset_key_message.html',
        }

But the email delivered is not containing HTML version.

I checked with the library's source and the dj_rest_auth/forms.py, the PasswordResetForm's save() method has the following code

context = {
    'current_site': current_site,
    'user': user,
    'password_reset_url': url,
    'request': request,
}
if app_settings.AUTHENTICATION_METHOD != app_settings.AuthenticationMethod.EMAIL:
    context['username'] = user_username(user)
get_adapter(request).send_mail(
    'account/email/password_reset_key', email, context
)

The passed kwargs are not being used in the context passed to the send_mail method, which the django.contrib.auth.forms.PasswordResetForm accepts the following

def send_mail(self, subject_template_name, email_template_name,
                  context, from_email, to_email, html_email_template_name=None):

What is the use of setting extra parameters in the serializer's get_email_options method?

anuj9196 avatar Aug 14 '21 10:08 anuj9196

Hi @anuj9196! I am currently having the same issue. We're you able to figure out a solution?

tarricsookdeo avatar Sep 16 '21 04:09 tarricsookdeo

Hi @tarricsookdeo Not yet. Please update if you get any solution.

anuj9196 avatar Sep 27 '21 02:09 anuj9196

Hi @anuj9196 @tarricsookdeo . Facing the same issue. In case any you guys get any resolution. Please share.

PavanKranthi avatar Dec 13 '21 16:12 PavanKranthi

Found multiple issues that seems related. I've given my solution in this comment that might help.

nibon avatar Dec 17 '21 12:12 nibon