From 22c07aa18b02467282ca6fe6e097e0e2ecbea18a Mon Sep 17 00:00:00 2001 From: Andrew Denisenko Date: Mon, 19 Oct 2020 23:04:50 +0300 Subject: [PATCH] fix files attaching to emails for remote storages Storages like S3, Dropbox, etc have no filefield.path() method - so submitting ticket with attachment leads to exception --- helpdesk/lib.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index afff47b5..637b3d1e 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -123,18 +123,8 @@ def send_templated_mail(template_name, if files: for filename, filefield in files: - mime = mimetypes.guess_type(filename) - if mime[0] is not None and mime[0] == "text/plain": - with open(filefield.path, 'r') as attachedfile: - content = attachedfile.read() - msg.attach(filename, content) - else: - if six.PY3: - msg.attach_file(filefield.path) - else: - with open(filefield.path, 'rb') as attachedfile: - content = attachedfile.read() - msg.attach(filename, content) + content = filefield.read() + msg.attach(filename, content) logger.debug('Sending email to: {!r}'.format(recipients))