Fix binary attachments to outgoing email, and handle case when it is plain text, to address #502

This commit is contained in:
Garret Wassermann 2017-07-17 05:04:25 -04:00
parent 4e81d64390
commit f6c323c9ab

View File

@ -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)