mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-20 01:27:44 +02:00
lib as reduxionist + read binary mode
This commit is contained in:
parent
df7920cd2e
commit
fc0ae58420
@ -21,6 +21,7 @@ except ImportError:
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.utils import six
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
@ -64,8 +65,6 @@ def send_templated_mail(template_name,
|
|||||||
"""
|
"""
|
||||||
from django.core.mail import EmailMultiAlternatives
|
from django.core.mail import EmailMultiAlternatives
|
||||||
from django.template import engines
|
from django.template import engines
|
||||||
from email.mime.base import MIMEBase
|
|
||||||
from email import encoders
|
|
||||||
from_string = engines['django'].from_string
|
from_string = engines['django'].from_string
|
||||||
|
|
||||||
from helpdesk.models import EmailTemplate
|
from helpdesk.models import EmailTemplate
|
||||||
@ -121,13 +120,12 @@ def send_templated_mail(template_name,
|
|||||||
recipients, bcc=bcc)
|
recipients, bcc=bcc)
|
||||||
msg.attach_alternative(html_part, "text/html")
|
msg.attach_alternative(html_part, "text/html")
|
||||||
|
|
||||||
if files:
|
for filename, filefield in files:
|
||||||
for file_name, file_field in files:
|
if six.PY3:
|
||||||
part_attachment = MIMEBase('application', "octet-stream")
|
msg.attach_file(filefield.path)
|
||||||
part_attachment.set_payload(open(file_field.path, 'rb').read())
|
else:
|
||||||
encoders.encode_base64(part_attachment)
|
with open(filefield.path, 'rb') as attachedfile:
|
||||||
part_attachment.add_header('Content-Disposition', 'attachment; filename="{}"'.format(file_name))
|
msg.attach(filename, attachedfile.read())
|
||||||
msg.attach(part_attachment)
|
|
||||||
|
|
||||||
return msg.send(fail_silently)
|
return msg.send(fail_silently)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user