Actually add more attachments
This commit is contained in:
parent
ba23234a15
commit
c088594e74
|
@ -1,3 +1,5 @@
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
from django.core.mail import EmailMultiAlternatives
|
from django.core.mail import EmailMultiAlternatives
|
||||||
from django.core.validators import validate_email
|
from django.core.validators import validate_email
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
@ -9,6 +11,7 @@ import logging, magic
|
||||||
|
|
||||||
logger = logging.getLogger("bornhack.%s" % __name__)
|
logger = logging.getLogger("bornhack.%s" % __name__)
|
||||||
|
|
||||||
|
Attachment = namedtuple('Attachment', field_names=['filename', 'content'])
|
||||||
|
|
||||||
def _send_email(
|
def _send_email(
|
||||||
text_template,
|
text_template,
|
||||||
|
@ -18,8 +21,7 @@ def _send_email(
|
||||||
bcc_recipients=[],
|
bcc_recipients=[],
|
||||||
html_template="",
|
html_template="",
|
||||||
sender="BornHack <info@bornhack.dk>",
|
sender="BornHack <info@bornhack.dk>",
|
||||||
attachments=(),
|
attachments=[],
|
||||||
attachment_filename="",
|
|
||||||
):
|
):
|
||||||
if not isinstance(to_recipients, list):
|
if not isinstance(to_recipients, list):
|
||||||
to_recipients = [to_recipients]
|
to_recipients = [to_recipients]
|
||||||
|
@ -45,8 +47,8 @@ def _send_email(
|
||||||
if attachments:
|
if attachments:
|
||||||
for attachment in attachments:
|
for attachment in attachments:
|
||||||
# figure out the mimetype
|
# figure out the mimetype
|
||||||
mimetype = magic.from_buffer(attachment, mime=True)
|
mimetype = magic.from_buffer(attachment.content, mime=True)
|
||||||
msg.attach(attachment_filename, attachment, mimetype)
|
msg.attach(attachment.filename, attachment.content, mimetype)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("exception while rendering email: {}".format(e))
|
logger.exception("exception while rendering email: {}".format(e))
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in a new issue