Skip to content

Commit

Permalink
add new setting A4_EMAIL_ATTACHMENTS for when you need more than th…
Browse files Browse the repository at this point in the history
…e `email_logo.png` attachement in your emails
  • Loading branch information
vellip authored and goapunk committed Jan 2, 2025
1 parent eb01981 commit 6420990
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
37 changes: 23 additions & 14 deletions adhocracy4/emails/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from email.mime.image import MIMEImage

from django.conf import settings
from django.contrib.staticfiles import finders
from django.core.mail import mail_admins

Expand All @@ -12,21 +13,29 @@ class PlatformEmailMixin:

def get_attachments(self):
attachments = super().get_attachments()
filename = finders.find("images/email_logo.png") or finders.find(
"images/email_logo.svg"
additional_files = getattr(
settings,
"A4_EMAIL_ATTACHMENTS",
[
("logo", "images/email_logo.svg"),
("logo", "images/email_logo.png"),
],
)
if filename:
if filename.endswith(".png"):
imagetype = "png"
else:
imagetype = "svg+xml"

with open(filename, "rb") as f:
logo = MIMEImage(f.read(), imagetype)

logo.add_header("Content-ID", "<{}>".format("logo"))
return attachments + [logo]
return attachments
files = []
for identifier, file in additional_files:
filename = finders.find(file)
if filename:
if filename.endswith(".png"):
imagetype = "png"
else:
imagetype = "svg+xml"

with open(filename, "rb") as f:
image = MIMEImage(f.read(), imagetype)

image.add_header("Content-ID", "<{}>".format(identifier))
files.append(image)
return attachments + files


class SyncEmailMixin:
Expand Down
3 changes: 3 additions & 0 deletions changelog/8527.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added
- new setting `A4_EMAIL_ATTACHMENTS` if you need more than the `email_logo.png` attachement in your emails
- this allows you to add custom attachments to the emails, even those set in a4

0 comments on commit 6420990

Please sign in to comment.