2013-06-05 07:26:53 +02:00
|
|
|
"""
|
|
|
|
|
The email task.
|
2013-08-15 23:41:03 +02:00
|
|
|
|
|
|
|
|
http://docs.python.org/2/library/email-examples.html
|
2013-06-18 00:10:14 +02:00
|
|
|
"""
|
|
|
|
|
|
2013-08-20 01:47:24 +02:00
|
|
|
#import smtplib
|
|
|
|
|
#from email.mime.text import MIMEText
|
2013-06-19 23:09:57 +02:00
|
|
|
from lib.tasks.task import Task
|
2013-06-18 00:10:14 +02:00
|
|
|
|
2013-06-18 02:58:40 +02:00
|
|
|
|
2013-06-18 00:10:14 +02:00
|
|
|
class EmailTask(Task):
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
|
if not "type" in kwargs:
|
|
|
|
|
raise Exception("'type' not in typeDict " + str(kwargs))
|
|
|
|
|
if not "args" in kwargs:
|
|
|
|
|
raise Exception("typeDict " + str(kwargs) + " has nor arguments!")
|
|
|
|
|
self.set_task_type(kwargs["type"])
|
|
|
|
|
self.recipient = kwargs["args"]["rcpt"]
|
|
|
|
|
|
2013-09-19 19:32:10 +02:00
|
|
|
def execute(self, msg):
|
2013-08-20 01:47:24 +02:00
|
|
|
'''
|
2013-08-15 22:32:15 +02:00
|
|
|
message = MIMEText(msg)
|
|
|
|
|
message['Subject'] = 'Warning from Linspector'
|
|
|
|
|
message['From'] = "warning@linspector.org"
|
2013-08-15 22:33:15 +02:00
|
|
|
message['To'] = self.recipient
|
2013-08-15 22:32:15 +02:00
|
|
|
s = smtplib.SMTP('localhost')
|
2013-08-15 22:33:15 +02:00
|
|
|
s.sendmail("warning@linspector.org", self.recipient, message.as_string())
|
2013-08-15 22:32:15 +02:00
|
|
|
s.quit()
|
2013-08-20 01:47:24 +02:00
|
|
|
'''
|
2013-09-19 19:32:10 +02:00
|
|
|
|
|
|
|
|
print("Task executed")
|
|
|
|
|
print(msg)
|
|
|
|
|
print(self.recipient)
|
2013-08-20 01:47:24 +02:00
|
|
|
pass
|
2013-06-18 00:10:14 +02:00
|
|
|
|
2013-09-19 19:32:10 +02:00
|
|
|
|
2013-06-19 01:39:25 +02:00
|
|
|
def create(taskDict):
|
2013-06-18 00:10:14 +02:00
|
|
|
return EmailTask(**taskDict)
|