the PLCAPI class requires __construct as well in order to move to php8
[plcapi.git] / PLC / sendmail.py
index dbaeaad..a1f2f3e 100644 (file)
@@ -1,8 +1,8 @@
 import os
 import sys
 import pprint
-from email.MIMEText import MIMEText
-from email.Header import Header
+from email.mime.text import MIMEText
+from email.header import Header
 from smtplib import SMTP
 
 from PLC.Logger import logger
@@ -32,7 +32,7 @@ def sendmail(api, To, Subject, Body, From = None, Cc = None, Bcc = None):
                 api.config.PLC_MAIL_SUPPORT_ADDRESS)
 
     # Create a MIME-encoded UTF-8 message
-    msg = MIMEText(Body.encode(api.encoding), _charset = api.encoding)
+    msg = MIMEText(Body)
 
     # Unicode subject headers are automatically encoded correctly
     msg['Subject'] = Subject
@@ -57,12 +57,8 @@ def sendmail(api, To, Subject, Body, From = None, Cc = None, Bcc = None):
         for addr in addresses:
             if isinstance(addr, tuple):
                 (name, addr) = addr
-                try:
-                    name = name.encode('ascii')
-                    header.append('%s <%s>' % (name, addr))
-                except:
-                    h = Header(name, charset = api.encoding, header_name = header_name)
-                    header.append('"%s" <%s>' % (h.encode(), addr))
+                h = Header(name, charset = api.encoding, header_name = header_name)
+                header.append('"%s" <%s>' % (h, addr))
             else:
                 header.append(addr)
             addrs.append(addr)