diff --git a/openslides/users/models.py b/openslides/users/models.py index 933839e2d..361d47c3b 100644 --- a/openslides/users/models.py +++ b/openslides/users/models.py @@ -254,7 +254,8 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser): except smtplib.SMTPDataError as e: error = e.smtp_code helptext = "" - if error == 554: + if error == 554: # The server does not accept our connection. The code is + # something like "transaction failed" or "No SMTP service here" helptext = " Is the email sender correct?" connection.close() raise ValidationError( @@ -262,6 +263,13 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser): ) except smtplib.SMTPRecipientsRefused: pass # Run into returning false later + except smtplib.SMTPAuthenticationError as e: + # Nice error message on auth failure + raise ValidationError( + { + "detail": f"Error {e.smtp_code}: Authentication failure. Please contact your local administrator." + } + ) else: if count == 1: self.email_send = True diff --git a/openslides/users/views.py b/openslides/users/views.py index 6116a7572..1b53d63c3 100644 --- a/openslides/users/views.py +++ b/openslides/users/views.py @@ -665,7 +665,21 @@ class PasswordResetView(APIView): subject = "".join(subject.splitlines()) from_email = None # TODO: Add nice from_email here. email_message = mail.EmailMessage(subject, body, from_email, [to_email]) - email_message.send() + try: + email_message.send() + except smtplib.SMTPRecipientsRefused: + raise ValidationError( + { + "detail": f"Error: The email to {to_email} was refused by the server. Please contact your local administrator." + } + ) + except smtplib.SMTPAuthenticationError as e: + # Nice error message on auth failure + raise ValidationError( + { + "detail": f"Error {e.smtp_code}: Authentication failure. Please contact your administrator." + } + ) return super().post(request, *args, **kwargs) def get_users(self, email):