From a6121c40f1753f49600eb866366c5594b912dfc6 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 16 Aug 2016 13:36:53 +0200 Subject: [PATCH] Added custom headers to mail() API --- src/pretix/base/services/mail.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pretix/base/services/mail.py b/src/pretix/base/services/mail.py index 2043a82fc..75555cfef 100644 --- a/src/pretix/base/services/mail.py +++ b/src/pretix/base/services/mail.py @@ -21,7 +21,7 @@ class TolerantDict(dict): def mail(email: str, subject: str, template: str, context: Dict[str, Any]=None, event: Event=None, locale: str=None, - order: Order=None): + order: Order=None, headers: dict=None): """ Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation. @@ -42,6 +42,8 @@ def mail(email: str, subject: str, template: str, :param order: The order this email is related to (optional). If set, this will be used to include a link to the order below the email. + :param headers: A dict of custom mail headers to add to the mail + :param locale: The locale to be used while evaluating the subject and the template :raises Exception: on obvious, immediate failures. Not raising an exception does not necessarily mean that the @@ -77,11 +79,11 @@ def mail(email: str, subject: str, template: str, 'secret': order.secret })) body += "\r\n" - return mail_send([email], subject, body, sender, event.id if event else None) + return mail_send([email], subject, body, sender, event.id if event else None, headers) -def mail_send(to: str, subject: str, body: str, sender: str, event: int=None) -> bool: - email = EmailMessage(subject, body, sender, to=to) +def mail_send(to: str, subject: str, body: str, sender: str, event: int=None, headers: dict=None) -> bool: + email = EmailMessage(subject, body, sender, to=to, headers=headers) if event: event = Event.objects.get(id=event) backend = event.get_mail_backend()