diff --git a/lims/entry.py b/lims/entry.py index 2d72cfe..0fcb33a 100644 --- a/lims/entry.py +++ b/lims/entry.py @@ -4,9 +4,10 @@ # the full copyright notices and license terms. import logging from datetime import datetime +from email import encoders from email.mime.base import MIMEBase +from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart -from email.mime.application import MIMEApplication from sql import Literal from trytond.model import Workflow, ModelView, ModelSQL, fields, Unique @@ -674,24 +675,23 @@ class Entry(Workflow, ModelSQL, ModelView): if not to_addrs: return None - msg = MIMEMultipart() + msg = MIMEMultipart('mixed') msg['From'] = from_addr hidden = True # TODO: HARDCODE! if not hidden: msg['To'] = ', '.join(to_addrs) msg['Subject'] = subject - msg_body = MIMEBase('text', 'plain') + msg_body = MIMEText('text', 'plain') msg_body.set_payload(body.encode('UTF-8'), 'UTF-8') msg.attach(msg_body) - attachment = MIMEApplication( - attachment_data['content'], - Name=attachment_data['filename'], _subtype="pdf") - attachment.add_header('content-disposition', 'attachment', - filename=('utf-8', '', attachment_data['filename'])) + attachment = MIMEBase('application', 'octet-stream') + attachment.set_payload(attachment_data['content']) + encoders.encode_base64(attachment) + attachment.add_header('Content-Disposition', 'attachment', + filename=attachment_data['filename']) msg.attach(attachment) - return msg def send_msg(self, from_addr, to_addrs, msg): diff --git a/lims_account_invoice/invoice.py b/lims_account_invoice/invoice.py index 5dad2af..c71a1d3 100644 --- a/lims_account_invoice/invoice.py +++ b/lims_account_invoice/invoice.py @@ -3,9 +3,10 @@ # The COPYRIGHT file at the top level of this repository contains # the full copyright notices and license terms. from datetime import datetime +from email import encoders from email.mime.base import MIMEBase +from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart -from email.mime.application import MIMEApplication from time import time import logging @@ -185,25 +186,24 @@ class Invoice(metaclass=PoolMeta): if not to_addrs: return None - msg = MIMEMultipart() + msg = MIMEMultipart('mixed') msg['From'] = from_addr hidden = True # TODO: HARDCODE! if not hidden: msg['To'] = ', '.join(to_addrs) msg['Subject'] = subject - msg_body = MIMEBase('text', 'plain') + msg_body = MIMEText('text', 'plain') msg_body.set_payload(body.encode('UTF-8'), 'UTF-8') msg.attach(msg_body) for attachment_data in attachments_data: - attachment = MIMEApplication( - attachment_data['content'], - Name=attachment_data['filename'], _subtype="pdf") - attachment.add_header('content-disposition', 'attachment', - filename=('utf-8', '', attachment_data['filename'])) + attachment = MIMEBase('application', 'octet-stream') + attachment.set_payload(attachment_data['content']) + encoders.encode_base64(attachment) + attachment.add_header('Content-Disposition', 'attachment', + filename=attachment_data['filename']) msg.attach(attachment) - return msg def send_msg(self, from_addr, to_addrs, msg): diff --git a/lims_email/results_report.py b/lims_email/results_report.py index f264f4c..8d343ed 100644 --- a/lims_email/results_report.py +++ b/lims_email/results_report.py @@ -3,9 +3,10 @@ # the full copyright notices and license terms. import logging from datetime import datetime +from email import encoders from email.mime.base import MIMEBase +from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart -from email.mime.application import MIMEApplication from string import Template from trytond.model import ModelSQL, ModelView, fields @@ -578,22 +579,22 @@ class SendResultsReport(Wizard): if not to_addrs: return None - msg = MIMEMultipart() + msg = MIMEMultipart('mixed') msg['From'] = from_addr if not hide_recipients: msg['To'] = ', '.join(to_addrs) msg['Subject'] = subject - msg_body = MIMEBase('text', 'plain') + msg_body = MIMEText('text', 'plain') msg_body.set_payload(body.encode('UTF-8'), 'UTF-8') msg.attach(msg_body) for attachment_data in attachments_data: - attachment = MIMEApplication( - attachment_data['content'], - Name=attachment_data['filename'], _subtype="pdf") - attachment.add_header('content-disposition', 'attachment', - filename=('utf-8', '', attachment_data['filename'])) + attachment = MIMEBase('application', 'octet-stream') + attachment.set_payload(attachment_data['content']) + encoders.encode_base64(attachment) + attachment.add_header('Content-Disposition', 'attachment', + filename=attachment_data['filename']) msg.attach(attachment) return msg diff --git a/lims_sale/sale.py b/lims_sale/sale.py index 7827a91..a7a21eb 100644 --- a/lims_sale/sale.py +++ b/lims_sale/sale.py @@ -2,10 +2,10 @@ # The COPYRIGHT file at the top level of this repository contains # the full copyright notices and license terms. import logging +from email import encoders from email.mime.base import MIMEBase +from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart -from email.mime.application import MIMEApplication -from email.header import Header from trytond.model import ModelSQL, ModelView, fields from trytond.wizard import Wizard, StateView, StateTransition, Button @@ -155,22 +155,22 @@ class Sale(metaclass=PoolMeta): if not (from_addr or to_addr): return None - msg = MIMEMultipart() + msg = MIMEMultipart('mixed') msg['From'] = from_addr msg['To'] = to_addr msg['Reply-to'] = reply_to - msg['Subject'] = Header(subject, 'utf-8') + msg['Subject'] = subject - msg_body = MIMEBase('text', 'plain') + msg_body = MIMEText('text', 'plain') msg_body.set_payload(body.encode('UTF-8'), 'UTF-8') msg.attach(msg_body) - attachment = MIMEApplication(attachment_data['content'], - Name=attachment_data['filename'], _subtype="pdf") - attachment.add_header('content-disposition', 'attachment', - filename=('utf-8', '', attachment_data['filename'])) + attachment = MIMEBase('application', 'octet-stream') + attachment.set_payload(attachment_data['content']) + encoders.encode_base64(attachment) + attachment.add_header('Content-Disposition', 'attachment', + filename=attachment_data['filename']) msg.attach(attachment) - return msg @staticmethod