Stéphane Wirtel <steph...@wirtel.be> added the comment:

Here is my suggestion

class SMTPSSLHander(SMTPHandler):
    def emit(self, record):
        """
        Emit a record.

        Format the record and send it to the specified addressees.
        """
        try:
            import smtplib
            from email.message import EmailMessage
            import email.utils

            port = self.mailport
            if not port:
                port = smtplib.SMTP_SSL_PORT
            keyfile = self.secure[0] if len(self.secure) > 0 else None
            certfile = self.secure[1] if len(self.secure) > 1 else None
            smtp = smtplib.SMTP_SSL(self.mailhost, port, timeout=self.timeout,
                                    keyfile=keyfile, certfile=certfile)
            if self.username:
                smtp.login(self.username, self.password)
            msg = EmailMessage()
            msg['From'] = self.fromaddr
            msg['To'] = ','.join(self.toaddrs)
            msg['Subject'] = self.getSubject(record)
            msg['Date'] = email.utils.localtime()
            msg.set_content(self.format(record))
            smtp.send_message(msg)
            smtp.quit()
        except Exception:
            self.handleError(record)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35995>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to