Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of SMTPRecipientsRefused exception #118

Open
weilu opened this issue Oct 4, 2021 · 0 comments
Open

Handling of SMTPRecipientsRefused exception #118

weilu opened this issue Oct 4, 2021 · 0 comments
Labels

Comments

@weilu
Copy link

weilu commented Oct 4, 2021

Following the docs on "How To Create Users Without Setting Their Password" https://django-authtools.readthedocs.io/en/latest/how-to/invitation-email.html (relevant code snippet below), the call to reset_form.save could trigger SMTPRecipientsRefused if the recipient email address is invalid, currently it will result in a 500 as-is. My understanding is that usually form error validations are handled in the clean_* method, any suggestions on how to deal with the SMTPRecipientsRefused exception in this case?

    def save_model(self, request, obj, form, change):
        if not change and (not form.cleaned_data['password1'] or not obj.has_usable_password()):
            # Django's PasswordResetForm won't let us reset an unusable
            # password. We set it above super() so we don't have to save twice.
            obj.set_password(get_random_string())
            reset_password = True
        else:
            reset_password = False

        super(UserAdmin, self).save_model(request, obj, form, change)

        if reset_password:
            reset_form = PasswordResetForm({'email': obj.email})
            assert reset_form.is_valid()
            reset_form.save(
                request=request,
                use_https=request.is_secure(),
                subject_template_name='registration/account_creation_subject.txt',
                email_template_name='registration/account_creation_email.html',
            )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants