8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-06-01 07:22:25 +00:00

Catch socket exceptions in mail_send

This commit is contained in:
Jean-Romain Garnier 2020-04-19 20:06:33 +00:00 committed by Gabriel Detraz
parent 69286beabf
commit 8e3e2249a6

View file

@ -29,14 +29,14 @@ from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail as django_send_mail
from django.contrib import messages
from smtplib import SMTPException
from socket import herror, gaierror
def send_mail(request, *args, **kwargs):
"""Wrapper for Django's send_mail which handles errors"""
try:
kwargs["fail_silently"] = request is None
django_send_mail(*args, **kwargs)
except (SMTPException, ConnectionError) as e:
except (SMTPException, ConnectionError, herror, gaierror) as e:
messages.error(
request,
_("Failed to send email: %(error)s.") % {
@ -49,7 +49,7 @@ def send_mail_object(mail, request):
"""Wrapper for Django's EmailMessage.send which handles errors"""
try:
mail.send()
except (SMTPException, ConnectionError) as e:
except (SMTPException, ConnectionError, herror, gaierror) as e:
if request:
messages.error(
request,