From 9939f62ebda35b6c14a3a7583c66c56a0594d24b Mon Sep 17 00:00:00 2001 From: Pawel M Date: Tue, 13 Dec 2016 23:28:16 +0100 Subject: [PATCH] Attachement should be readed in binary mode ... and attached as payload (regarding docs) --- helpdesk/lib.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index a87821ce..ac309df5 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -118,11 +118,14 @@ def send_templated_mail(template_name, sender or settings.DEFAULT_FROM_EMAIL, recipients, bcc=bcc) msg.attach_alternative(html_part, "text/html") - + if files: for file_name, file_field in files: - with open(file_field.path, 'rb') as attached_file: - msg.attach(file_name, attached_file.read(), getattr(attached_file, 'content_type', None)) + part_attachment = MIMEBase('application', "octet-stream") + part_attachment.set_payload(open(file_field.path, 'rb').read()) + encoders.encode_base64(part_attachment) + part_attachment.add_header('Content-Disposition', 'attachment; filename="{}"'.format(file_name)) + msg.attach(part_attachment) return msg.send(fail_silently)