Sending Email

pretix allows event organizers to configure how they want to send emails to their users in multiple ways. Therefore, all emails should be sent through the following function.

If the email you send is related to an order, you should also take a look at the send_mail() of the order model.

pretix.base.services.mail.mail(email: str, subject: str, template: typing.Union[str, i18nfield.strings.LazyI18nString], context: typing.Dict[str, typing.Any] = None, event: pretix.base.models.event.Event = None, locale: str = None, order: pretix.base.models.orders.Order = None, headers: dict = None, sender: str = None, invoices: list = None, attach_tickets=False)

Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation.

Parameters:
  • email – The email address of the recipient
  • subject – The email subject. Should be localized to the recipients’s locale or a lazy object that will be localized by being casted to a string.
  • template – The filename of a template to be used. It will be rendered with the locale given in the locale argument and the context given in the next argument. Alternatively, you can pass a LazyI18nString and context will be used as the argument to a Python .format_map() call on the template.
  • context – The context for rendering the template (see template parameter)
  • event – The event this email is related to (optional). If set, this will be used to determine the sender, a possible prefix for the subject and the SMTP server that should be used to send this email.
  • 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.
  • headers – A dict of custom mail headers to add to the mail
  • locale – The locale to be used while evaluating the subject and the template
  • sender – Set the sender email address. If not set and event is set, the event’s default will be used, otherwise the system default.
  • invoices – A list of invoices to attach to this email.
  • attach_tickets – Whether to attach tickets to this email, if they are available to download.
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.