Merge pull request #375 from bornhack/more_attachments
More attachments
This commit is contained in:
commit
99977759ee
|
@ -20,6 +20,7 @@ def _send_email(
|
||||||
sender="BornHack <info@bornhack.dk>",
|
sender="BornHack <info@bornhack.dk>",
|
||||||
attachment=None,
|
attachment=None,
|
||||||
attachment_filename="",
|
attachment_filename="",
|
||||||
|
attachments=None,
|
||||||
):
|
):
|
||||||
if not isinstance(to_recipients, list):
|
if not isinstance(to_recipients, list):
|
||||||
to_recipients = [to_recipients]
|
to_recipients = [to_recipients]
|
||||||
|
@ -41,11 +42,15 @@ def _send_email(
|
||||||
if html_template:
|
if html_template:
|
||||||
msg.attach_alternative(html_template, "text/html")
|
msg.attach_alternative(html_template, "text/html")
|
||||||
|
|
||||||
|
if not attachments and attachment:
|
||||||
|
attachments = [(attachment, attachment_filename)]
|
||||||
|
|
||||||
# is there an attachment to this mail?
|
# is there an attachment to this mail?
|
||||||
if attachment:
|
if attachments:
|
||||||
# figure out the mimetype
|
for content, filename in attachments:
|
||||||
mimetype = magic.from_buffer(attachment, mime=True)
|
# figure out the mimetype
|
||||||
msg.attach(attachment_filename, attachment, mimetype)
|
mimetype = magic.from_buffer(content, mime=True)
|
||||||
|
msg.attach(filename, 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