Sendmail plugin: Allow to attach a file to emails (#1814)

* sendmail: allow to attach files to emails

* Fix mixup of model objects and model IDs

* Attach to order-level emails, not only position-level emails

* Give attachments a proper file type

* Add a warning note about higher spam chances

Co-authored-by: Raphael Michel <mail@raphaelmichel.de>
This commit is contained in:
Sohalt
2020-10-22 09:53:19 +02:00
committed by GitHub
parent d673a43130
commit 9e4dc344a4
5 changed files with 51 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ from i18nfield.forms import I18nFormField, I18nTextarea, I18nTextInput
from pretix.base.email import get_available_placeholders
from pretix.base.forms import PlaceholderValidator
from pretix.base.models import CheckinList, Item, Order, SubEvent
from pretix.control.forms import ExtFileField
from pretix.control.forms.widgets import Select2, Select2Multiple
@@ -20,6 +21,18 @@ class MailForm(forms.Form):
sendto = forms.MultipleChoiceField() # overridden later
subject = forms.CharField(label=_("Subject"))
message = forms.CharField(label=_("Message"))
attachment = ExtFileField(
label=_("Attachment"),
required=False,
ext_whitelist=(
".png", ".jpg", ".gif", ".jpeg", ".pdf", ".txt", ".docx", ".gif", ".svg",
".pptx", ".ppt", ".doc", ".xlsx", ".xls", ".jfif", ".heic", ".heif", ".pages",
".bmp", ".tif", ".tiff"
),
help_text=_('Sending an attachment increases the chance of your email not arriving or being sorted into spam folders. We recommend only using PDFs '
'of no more than 2 MB in size.'),
max_size=10 * 1024 * 1024
) # TODO i18n
items = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple(
attrs={'class': 'scrolling-multiple-choice'}