Make mail() raise an exception on obvious failures

As per #164. Should also work for #69.
This commit is contained in:
Tobias Kunze
2016-08-09 21:39:08 +02:00
parent 04ab016d91
commit 980e0f5eb3

View File

@@ -44,8 +44,8 @@ def mail(email: str, subject: str, template: str,
:param locale: The locale to be used while evaluating the subject and the template :param locale: The locale to be used while evaluating the subject and the template
:return: ``False`` on obvious, immediate failures, ``True`` otherwise. ``True`` does not necessarily mean that :raises Exception: on obvious, immediate failures. Not raising an exception does not necessarily mean that the
the email has been sent, just that it has been queued by the email backend. email has been sent, just that it has been queued by the email backend.
""" """
with language(locale): with language(locale):
if isinstance(template, LazyI18nString): if isinstance(template, LazyI18nString):
@@ -90,10 +90,9 @@ def mail_send(to: str, subject: str, body: str, sender: str, event: int=None) ->
try: try:
backend.send_messages([email]) backend.send_messages([email])
return True
except Exception: except Exception:
logger.exception('Error sending email') logger.exception('Error sending email')
return False raise
if settings.HAS_CELERY and settings.EMAIL_BACKEND != 'django.core.mail.outbox': if settings.HAS_CELERY and settings.EMAIL_BACKEND != 'django.core.mail.outbox':