ndl: improve emails

This commit is contained in:
Vladislav Yarmak 2019-08-21 00:48:46 +03:00
parent 0c7847b591
commit 353e0568c4

View File

@ -97,6 +97,7 @@ class EmailNotifier(BaseNotifier):
'email.mime.multipart').MIMEMultipart 'email.mime.multipart').MIMEMultipart
self._MIMEBase = importlib.import_module('email.mime.base').MIMEBase self._MIMEBase = importlib.import_module('email.mime.base').MIMEBase
self._encoders = importlib.import_module('email.encoders') self._encoders = importlib.import_module('email.encoders')
self._mimeheader = importlib.import_module('email.header').Header
self._m = self._Mailer(from_addr=from_addr, self._m = self._Mailer(from_addr=from_addr,
host=host, host=host,
port=port, port=port,
@ -110,13 +111,16 @@ class EmailNotifier(BaseNotifier):
def notify(self, obj): def notify(self, obj):
msg = self._MIMEMult() msg = self._MIMEMult()
msg['Subject'] = "New Nvidia driver available!" msg['Subject'] = self._mimeheader("New Nvidia driver available!", "utf-8")
msg['From'] = self._from_addr msg['From'] = self._from_addr
msg['To'] = ', '.join(self._to_addrs) msg['To'] = ', '.join(self._to_addrs)
body = "See attached JSON" obj_text = json.dumps(obj, indent=4, ensure_ascii=False)
msg.attach(self._MIMEText(body, 'plain')) msg_text = json.dumps(obj, indent=4, ensure_ascii=True)
body = "See attached JSON or message body below:\n"
body += msg_text
msg.attach(self._MIMEText(body, 'plain', 'utf-8'))
p = self._MIMEBase('application', 'octet-stream') p = self._MIMEBase('application', 'octet-stream')
p.set_payload(json.dumps(obj, indent=4).encode('utf-8')) p.set_payload(obj_text.encode('ascii'))
self._encoders.encode_base64(p) self._encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename=obj.json") p.add_header('Content-Disposition', "attachment; filename=obj.json")
msg.attach(p) msg.attach(p)