Prevent autoresponders

This commit is contained in:
Raphael Michel
2019-08-14 10:28:53 +02:00
parent 0582a4d9e5
commit 200ce93bb4
3 changed files with 9 additions and 4 deletions

View File

@@ -697,7 +697,7 @@ class Order(LockModel, LoggedModel):
def send_mail(self, subject: str, template: Union[str, LazyI18nString], def send_mail(self, subject: str, template: Union[str, LazyI18nString],
context: Dict[str, Any]=None, log_entry_type: str='pretix.event.order.email.sent', context: Dict[str, Any]=None, log_entry_type: str='pretix.event.order.email.sent',
user: User=None, headers: dict=None, sender: str=None, invoices: list=None, user: User=None, headers: dict=None, sender: str=None, invoices: list=None,
auth=None, attach_tickets=False, position: 'OrderPosition'=None): auth=None, attach_tickets=False, position: 'OrderPosition'=None, auto_email=True):
""" """
Sends an email to the user that placed this order. Basically, this method does two things: Sends an email to the user that placed this order. Basically, this method does two things:
@@ -737,7 +737,7 @@ class Order(LockModel, LoggedModel):
recipient, subject, template, context, recipient, subject, template, context,
self.event, self.locale, self, headers=headers, sender=sender, self.event, self.locale, self, headers=headers, sender=sender,
invoices=invoices, attach_tickets=attach_tickets, invoices=invoices, attach_tickets=attach_tickets,
position=position position=position, auto_email=auto_email
) )
except SendMailException: except SendMailException:
raise raise

View File

@@ -51,7 +51,7 @@ class SendMailException(Exception):
def mail(email: str, subject: str, template: Union[str, LazyI18nString], def mail(email: str, subject: str, template: Union[str, LazyI18nString],
context: Dict[str, Any]=None, event: Event=None, locale: str=None, context: Dict[str, Any]=None, event: Event=None, locale: str=None,
order: Order=None, position: OrderPosition=None, headers: dict=None, sender: str=None, order: Order=None, position: OrderPosition=None, headers: dict=None, sender: str=None,
invoices: list=None, attach_tickets=False): invoices: list=None, attach_tickets=False, auto_email=True):
""" """
Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation. Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation.
@@ -86,6 +86,8 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString],
:param attach_tickets: Whether to attach tickets to this email, if they are available to download. :param attach_tickets: Whether to attach tickets to this email, if they are available to download.
:param auto_email: Whether this email is auto-generated
:raises MailOrderException: on obvious, immediate failures. Not raising an exception does not necessarily mean :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. that the email has been sent, just that it has been queued by the email backend.
""" """
@@ -93,6 +95,9 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString],
return return
headers = headers or {} headers = headers or {}
if auto_email:
headers['X-Auto-Response-Suppress'] = 'OOF, NRN, AutoReply, RN'
headers['Auto-Submitted'] = 'auto-generated'
with language(locale): with language(locale):
if isinstance(context, dict) and event: if isinstance(context, dict) and event:

View File

@@ -1525,7 +1525,7 @@ class OrderSendMail(EventPermissionRequiredMixin, OrderViewMixin, FormView):
order.send_mail( order.send_mail(
form.cleaned_data['subject'], email_template, form.cleaned_data['subject'], email_template,
email_context, 'pretix.event.order.email.custom_sent', email_context, 'pretix.event.order.email.custom_sent',
self.request.user self.request.user, auto_email=False
) )
messages.success(self.request, messages.success(self.request,
_('Your message has been queued and will be sent to {}.'.format(order.email))) _('Your message has been queued and will be sent to {}.'.format(order.email)))