Remove multiple attachment code - was not even done

This commit is contained in:
Víðir Valberg Guðmundsson 2019-08-08 10:26:47 +02:00
parent 2751b92cb8
commit 2ba70c692f

View file

@ -20,7 +20,6 @@ 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]
@ -42,15 +41,11 @@ 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 attachments: if attachment
for content, filename in attachments: # figure out the mimetype
# figure out the mimetype mimetype = magic.from_buffer(attachment, mime=True)
mimetype = magic.from_buffer(content, mime=True) msg.attach(attachment_filename, attachment, mimetype)
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
@ -76,6 +71,7 @@ def add_outgoing_email(
sender="BornHack <info@bornhack.dk>", sender="BornHack <info@bornhack.dk>",
attachment=None, attachment=None,
attachment_filename="", attachment_filename="",
attachments=None,
): ):
""" adds an email to the outgoing queue """ adds an email to the outgoing queue
recipients is a list of to recipients recipients is a list of to recipients
@ -104,9 +100,4 @@ def add_outgoing_email(
bcc_recipients=bcc_recipients, bcc_recipients=bcc_recipients,
) )
if attachment:
django_file = ContentFile(attachment)
django_file.name = attachment_filename
email.attachment.save(attachment_filename, django_file, save=True)
return True return True