linspector-old/lib/tasks/email.py

37 lines
1,006 B
Python
Raw Normal View History

"""
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):
2013-08-20 01:47:24 +02:00
pass
'''
2013-06-18 00:10:14 +02:00
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-08-20 01:47:24 +02:00
'''
2013-06-18 00:10:14 +02:00
def execute_task(self, msg):
2013-08-20 01:47:24 +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
s = smtplib.SMTP('localhost')
2013-08-15 22:33:15 +02:00
s.sendmail("warning@linspector.org", self.recipient, message.as_string())
s.quit()
2013-08-20 01:47:24 +02:00
'''
pass
2013-06-18 00:10:14 +02:00
def create(taskDict):
2013-06-18 00:10:14 +02:00
return EmailTask(**taskDict)