Multiple attachments on mails

This commit is contained in:
Víðir Valberg Guðmundsson 2019-08-07 23:25:52 +02:00
parent 943dcf8abd
commit ba23234a15

View file

@ -18,7 +18,7 @@ def _send_email(
bcc_recipients=[], bcc_recipients=[],
html_template="", html_template="",
sender="BornHack <info@bornhack.dk>", sender="BornHack <info@bornhack.dk>",
attachment=None, attachments=(),
attachment_filename="", attachment_filename="",
): ):
if not isinstance(to_recipients, list): if not isinstance(to_recipients, list):
@ -42,10 +42,11 @@ def _send_email(
msg.attach_alternative(html_template, "text/html") msg.attach_alternative(html_template, "text/html")
# is there an attachment to this mail? # is there an attachment to this mail?
if attachment: if attachments:
# figure out the mimetype for attachment in attachments:
mimetype = magic.from_buffer(attachment, mime=True) # figure out the mimetype
msg.attach(attachment_filename, attachment, mimetype) mimetype = magic.from_buffer(attachment, mime=True)
msg.attach(attachment_filename, attachment, 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