Catch more email exceptiopns
This commit is contained in:
parent
29762ad89e
commit
b058bda4f6
@ -254,7 +254,8 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser):
|
|||||||
except smtplib.SMTPDataError as e:
|
except smtplib.SMTPDataError as e:
|
||||||
error = e.smtp_code
|
error = e.smtp_code
|
||||||
helptext = ""
|
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?"
|
helptext = " Is the email sender correct?"
|
||||||
connection.close()
|
connection.close()
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
@ -262,6 +263,13 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser):
|
|||||||
)
|
)
|
||||||
except smtplib.SMTPRecipientsRefused:
|
except smtplib.SMTPRecipientsRefused:
|
||||||
pass # Run into returning false later
|
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:
|
else:
|
||||||
if count == 1:
|
if count == 1:
|
||||||
self.email_send = True
|
self.email_send = True
|
||||||
|
@ -665,7 +665,21 @@ class PasswordResetView(APIView):
|
|||||||
subject = "".join(subject.splitlines())
|
subject = "".join(subject.splitlines())
|
||||||
from_email = None # TODO: Add nice from_email here.
|
from_email = None # TODO: Add nice from_email here.
|
||||||
email_message = mail.EmailMessage(subject, body, from_email, [to_email])
|
email_message = mail.EmailMessage(subject, body, from_email, [to_email])
|
||||||
|
try:
|
||||||
email_message.send()
|
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)
|
return super().post(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_users(self, email):
|
def get_users(self, email):
|
||||||
|
Loading…
Reference in New Issue
Block a user