mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-20 09:37:48 +02:00
Fix binary attachments to outgoing email, and handle case when it is plain text, to address #502
This commit is contained in:
parent
4e81d64390
commit
f6c323c9ab
@ -117,7 +117,15 @@ def send_templated_mail(template_name,
|
|||||||
|
|
||||||
if files:
|
if files:
|
||||||
for filename, filefield in files:
|
for filename, filefield in files:
|
||||||
msg.attach(filename, open(filefield.path).read())
|
mime = mimetypes.guess_type(filename)
|
||||||
|
if mime[0] is not None and mime[0] == "text/plain":
|
||||||
|
with open(filefield.path, 'r') as file:
|
||||||
|
content = file.read()
|
||||||
|
msg.attach(filename, content)
|
||||||
|
else:
|
||||||
|
with open(filefield.path, 'rb') as file:
|
||||||
|
content = file.read()
|
||||||
|
msg.attach(filename, content)
|
||||||
|
|
||||||
return msg.send(fail_silently)
|
return msg.send(fail_silently)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user