diff --git a/src/pretix/base/models/auth.py b/src/pretix/base/models/auth.py index 2cd4d0f08..9ec667847 100644 --- a/src/pretix/base/models/auth.py +++ b/src/pretix/base/models/auth.py @@ -176,6 +176,7 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin): 'url': build_absolute_uri('control:user.settings') }, event=None, + user=self, locale=self.locale ) except SendMailException: @@ -191,7 +192,7 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin): 'url': (build_absolute_uri('control:auth.forgot.recover') + '?id=%d&token=%s' % (self.id, default_token_generator.make_token(self))) }, - None, locale=self.locale + None, locale=self.locale, user=self ) @property diff --git a/src/pretix/base/services/mail.py b/src/pretix/base/services/mail.py index 7fcb126d8..16508c8aa 100644 --- a/src/pretix/base/services/mail.py +++ b/src/pretix/base/services/mail.py @@ -24,7 +24,7 @@ from i18nfield.strings import LazyI18nString from pretix.base.email import ClassicMailRenderer from pretix.base.i18n import language from pretix.base.models import ( - Event, Invoice, InvoiceAddress, Order, OrderPosition, + Event, Invoice, InvoiceAddress, Order, OrderPosition, User, ) from pretix.base.services.invoices import invoice_pdf_task from pretix.base.services.tasks import TransactionAwareTask @@ -51,7 +51,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, position: OrderPosition=None, headers: dict=None, sender: str=None, - invoices: list=None, attach_tickets=False, auto_email=True): + invoices: list=None, attach_tickets=False, auto_email=True, user=None): """ Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation. @@ -88,6 +88,8 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString], :param auto_email: Whether this email is auto-generated + :param user: The user this email is sent to + :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. """ @@ -214,7 +216,8 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString], invoices=[i.pk for i in invoices] if invoices and not position else [], order=order.pk if order else None, position=position.pk if position else None, - attach_tickets=attach_tickets + attach_tickets=attach_tickets, + user=user.pk if user else None ) if invoices: @@ -229,13 +232,16 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString], @app.task(base=TransactionAwareTask, bind=True) def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: str, sender: str, event: int=None, position: int=None, headers: dict=None, bcc: List[str]=None, - invoices: List[int]=None, order: int=None, attach_tickets=False) -> bool: + invoices: List[int]=None, order: int=None, attach_tickets=False, user=None) -> bool: email = EmailMultiAlternatives(subject, body, sender, to=to, bcc=bcc, headers=headers) if html is not None: html_with_cid, cid_images = replace_images_with_cid_paths(html) email = attach_cid_images(email, cid_images, verify_ssl=True) email.attach_alternative(html_with_cid, "text/html") + if user: + user = User.objects.get(pk=user) + if event: with scopes_disabled(): event = Event.objects.get(id=event) @@ -297,7 +303,7 @@ def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: st } ) - email = email_filter.send_chained(event, 'message', message=email, order=order) + email = email_filter.send_chained(event, 'message', message=email, order=order, user=user) try: backend.send_messages([email]) diff --git a/src/pretix/base/services/notifications.py b/src/pretix/base/services/notifications.py index 3bcd1d3c0..5d50a66ec 100644 --- a/src/pretix/base/services/notifications.py +++ b/src/pretix/base/services/notifications.py @@ -120,4 +120,5 @@ def send_notification_mail(notification: Notification, user: User): 'html': body_html, 'sender': settings.MAIL_FROM, 'headers': {}, + 'user': user.pk }) diff --git a/src/pretix/base/signals.py b/src/pretix/base/signals.py index ea2ff5508..30a54e230 100644 --- a/src/pretix/base/signals.py +++ b/src/pretix/base/signals.py @@ -500,7 +500,7 @@ As with all event-plugin signals, the ``sender`` keyword argument will contain t """ email_filter = EventPluginSignal( - providing_args=['message', 'order'] + providing_args=['message', 'order', 'user'] ) """ This signal allows you to implement a middleware-style filter on all outgoing emails. You are expected to @@ -510,6 +510,8 @@ As with all event-plugin signals, the ``sender`` keyword argument will contain t The ``message`` argument will contain an ``EmailMultiAlternatives`` object. If the email is associated with a specific order, the ``order`` argument will be passed as well, otherwise it will be ``None``. +If the email is associated with a specific user, e.g. a notification email, the ``user`` argument will be passed as +well, otherwise it will be ``None``. """