From 5670c92d3354dcd11a49941ad0a84875a36c5574 Mon Sep 17 00:00:00 2001 From: b3yond Date: Thu, 29 Mar 2018 00:31:21 +0200 Subject: [PATCH] added logging to sendmail.py --- sendmail.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sendmail.py b/sendmail.py index 93028d9..1579165 100755 --- a/sendmail.py +++ b/sendmail.py @@ -6,6 +6,14 @@ from config import config from email.mime.text import MIMEText from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart +import logging + + +logpath = config['logging']['logpath'] +logger = logging.getLogger() +fh = logging.FileHandler(logpath) +fh.setLevel(logging.DEBUG) +logger.addHandler(fh) class Mailer(object): @@ -26,7 +34,10 @@ class Mailer(object): # starts a client session with the SMTP server self.s = smtplib.SMTP(config["mail"]["mailserver"]) - context = ssl.create_default_context() + try: + context = ssl.create_default_context() + except: + logger.error('Creating SSL Context failed.', exc_info=True) self.s.starttls(context=context) self.s.login(config["mail"]["user"], config["mail"]["passphrase"])