From 980e0f5eb319540ae405f4a08bbb453a94af9e9d Mon Sep 17 00:00:00 2001 From: Tobias Kunze Date: Tue, 9 Aug 2016 21:39:08 +0200 Subject: [PATCH] Make mail() raise an exception on obvious failures As per #164. Should also work for #69. --- src/pretix/base/services/mail.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pretix/base/services/mail.py b/src/pretix/base/services/mail.py index 09cec00977..0cc0a07ba8 100644 --- a/src/pretix/base/services/mail.py +++ b/src/pretix/base/services/mail.py @@ -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 - :return: ``False`` on obvious, immediate failures, ``True`` otherwise. ``True`` does not necessarily mean that - the email has been sent, just that it has been queued by the email backend. + :raises Exception: on obvious, immediate failures. Not raising an exception does not necessarily mean that the + email has been sent, just that it has been queued by the email backend. """ with language(locale): if isinstance(template, LazyI18nString): @@ -90,10 +90,9 @@ def mail_send(to: str, subject: str, body: str, sender: str, event: int=None) -> try: backend.send_messages([email]) - return True except Exception: logger.exception('Error sending email') - return False + raise if settings.HAS_CELERY and settings.EMAIL_BACKEND != 'django.core.mail.outbox':