mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-29 03:13:15 +01: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:
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user