mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-08-10 00:17:54 +02:00
Fix binary attachments to outgoing email, and handle case when it is plain text, to address #502
This commit is contained in:
@ -117,7 +117,15 @@ def send_templated_mail(template_name,
|
||||
|
||||
if 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)
|
||||
|
||||
|
Reference in New Issue
Block a user