From 5086520ed2c0fe1e67750742ec125be65a5f6e75 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Fri, 22 Nov 2013 19:41:59 +0100 Subject: [PATCH] added authentication to mail task --- linspector/tasks/alert/mail.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/linspector/tasks/alert/mail.py b/linspector/tasks/alert/mail.py index e587846..cced1c8 100644 --- a/linspector/tasks/alert/mail.py +++ b/linspector/tasks/alert/mail.py @@ -23,7 +23,6 @@ along with this program. If not, see . import datetime import smtplib -import time from email.mime.text import MIMEText from logging import getLogger @@ -57,7 +56,13 @@ class MailTask(Task): if "port" in args: self.port = args["port"] - # ...and so on for all possible args + self.username = None + if "username" in args: + self.username = args["username"] + + self.password = None + if "password" in args: + self.password = args["password"] def execute(self, job_information): logger.debug("Executing Mail Task!") @@ -68,8 +73,15 @@ class MailTask(Task): message['Date'] = now.strftime("%a, %d %b %Y %H:%M:%S") message['From'] = self.sender message['To'] = self.rcpt + s = smtplib.SMTP(self.host, self.port) - #s.login(self.userName, self.password) + + if self.username and self.password: + try: + s.login(self.username, self.password) + except Exception, e: + logger.warning(e) + s.sendmail(self.sender, self.rcpt, message.as_string()) s.quit()