changed mail task according to new config
Q
This commit is contained in:
parent
f82f2f8239
commit
4be1a6ecb9
2 changed files with 23 additions and 10 deletions
|
|
@ -33,13 +33,23 @@ logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MailTask(Task):
|
class MailTask(Task):
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if not "type" in kwargs:
|
mandatory_args = ["host", "password", "from", "username"]
|
||||||
raise Exception("'type' not in typeDict " + str(kwargs))
|
for arg in mandatory_args:
|
||||||
if not "args" in kwargs:
|
if not arg in kwargs:
|
||||||
raise Exception("typeDict " + str(kwargs) + " has no arguments!")
|
self.raise_config_exception(kwargs, arg)
|
||||||
self.set_task_type(kwargs["type"])
|
self.host = kwargs["host"]
|
||||||
self.recipient = kwargs["args"]["rcpt"]
|
self.password = kwargs["password"]
|
||||||
|
self.fromName = kwargs["from"]
|
||||||
|
self.userName = kwargs["username"]
|
||||||
|
self.port = 25
|
||||||
|
if "port" in kwargs:
|
||||||
|
self.port = kwargs["port"]
|
||||||
|
|
||||||
|
#self.set_task_type(kwargs["type"])
|
||||||
|
#self.recipient = kwargs["args"]["rcpt"]
|
||||||
|
|
||||||
def execute(self, msg, core):
|
def execute(self, msg, core):
|
||||||
message = MIMEText(msg)
|
message = MIMEText(msg)
|
||||||
|
|
@ -47,11 +57,11 @@ class MailTask(Task):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
message['Date'] = now.strftime("%a, %d %b %Y %H:%M:%S")
|
message['Date'] = now.strftime("%a, %d %b %Y %H:%M:%S")
|
||||||
#TODO: totally unstable just to use values from core. make checks before...!
|
#TODO: totally unstable just to use values from core. make checks before...!
|
||||||
message['From'] = core["tasks"]["mail"]["from"]
|
message['From'] = self.fromName
|
||||||
message['To'] = self.recipient
|
message['To'] = self.recipient
|
||||||
s = smtplib.SMTP(core["tasks"]["mail"]["host"], core["tasks"]["mail"]["port"])
|
s = smtplib.SMTP(self.host, self.port)
|
||||||
s.login(core["tasks"]["mail"]["username"], core["tasks"]["mail"]["password"])
|
s.login(self.userName, self.password)
|
||||||
s.sendmail(core["tasks"]["mail"]["from"], self.recipient, message.as_string())
|
s.sendmail(self.fromName, self.recipient, message.as_string())
|
||||||
s.quit()
|
s.quit()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Task:
|
class Task:
|
||||||
|
def raise_config_exception(self, typeDict, name):
|
||||||
|
raise Exception("typeDict " + str(typeDict) + " has no " + str(name) + " argument!")
|
||||||
|
|
||||||
def set_task_type(self, taskType):
|
def set_task_type(self, taskType):
|
||||||
self._taskType = taskType
|
self._taskType = taskType
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue