From fa6102bbad46758325aa6594845455eaf3ad9c23 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 6 Jul 2017 18:06:07 +0200 Subject: [PATCH] Allow to override sender for mail --- src/pretix/base/services/mail.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pretix/base/services/mail.py b/src/pretix/base/services/mail.py index 4076bb4e71..1db77717b3 100644 --- a/src/pretix/base/services/mail.py +++ b/src/pretix/base/services/mail.py @@ -33,7 +33,7 @@ class SendMailException(Exception): def mail(email: str, subject: str, template: Union[str, LazyI18nString], context: Dict[str, Any]=None, event: Event=None, locale: str=None, - order: Order=None, headers: dict=None): + order: Order=None, headers: dict=None, sender: str=None): """ Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation. @@ -58,6 +58,9 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString], :param locale: The locale to be used while evaluating the subject and the template + :param sender: Set the sender email address. If not set and ``event`` is set, the event's default will be used, + otherwise the system default. + :raises MailOrderException: 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. """ @@ -90,7 +93,7 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString], body = tpl.render(context) body_md = bleach.linkify(markdown.markdown(body)) - sender = event.settings.get('mail_from') if event else settings.MAIL_FROM + sender = sender or (event.settings.get('mail_from') if event else settings.MAIL_FROM) subject = str(subject) body_plain = body