mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Catch socket exceptions in mail_send
This commit is contained in:
parent
528bfcdef3
commit
f3ae1973a1
1 changed files with 3 additions and 3 deletions
|
@ -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.core.mail import send_mail as django_send_mail
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from smtplib import SMTPException
|
from smtplib import SMTPException
|
||||||
|
from socket import herror, gaierror
|
||||||
|
|
||||||
def send_mail(request, *args, **kwargs):
|
def send_mail(request, *args, **kwargs):
|
||||||
"""Wrapper for Django's send_mail which handles errors"""
|
"""Wrapper for Django's send_mail which handles errors"""
|
||||||
try:
|
try:
|
||||||
kwargs["fail_silently"] = request is None
|
kwargs["fail_silently"] = request is None
|
||||||
django_send_mail(*args, **kwargs)
|
django_send_mail(*args, **kwargs)
|
||||||
except (SMTPException, ConnectionError) as e:
|
except (SMTPException, ConnectionError, herror, gaierror) as e:
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
_("Failed to send email: %(error)s.") % {
|
_("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"""
|
"""Wrapper for Django's EmailMessage.send which handles errors"""
|
||||||
try:
|
try:
|
||||||
mail.send()
|
mail.send()
|
||||||
except (SMTPException, ConnectionError) as e:
|
except (SMTPException, ConnectionError, herror, gaierror) as e:
|
||||||
if request:
|
if request:
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
|
|
Loading…
Reference in a new issue