Added a mailer agent, modified the configuration to handle mailer and factory for transport

master
Steve L. Nyemba 8 years ago
parent 1fa603ae3c
commit 5eb6f44cb2

@ -40,16 +40,12 @@ f = open(PARAMS['path'])
CONFIG = json.loads(f.read())
HANDLERS= {}
for key in CONFIG :
if key == "monitor":
continue
className = CONFIG[key]['class']
for key in CONFIG['monitor'] :
className = CONFIG['monitor'][key]['class']
ref = "".join(["monitor.",className,"()"])
ref = eval(ref)
#ref.init(CONFIG[key]['config'])
HANDLERS[key] = {"class":ref,"config":CONFIG[key]["config"]}
HANDLERS[key] = {"class":ref,"config":CONFIG['monitor'][key]["config"]}
f.close()

@ -0,0 +1,38 @@
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
class MailAgent :
def __init__(self,conf) :
self.uid = conf['uid']
try:
self.handler = smtplib.SMTP_SSL(conf['host'],conf['port'])
r = self.handler.login(self.uid,conf['password'])
#
# @TODO: Check the status of the authentication
# If not authenticated the preconditions have failed
#
except Exception,e:
print e
self.handler = None
pass
def send(self,**args) :
subject = args['subject']
message = args['message']
to = args['to']
if '<' in message and '>' in message :
message = MIMEText(message,'html')
else:
message = MIMEText(message,'plain')
message['From'] = self.uid
message['To'] = to
message['Subject'] = subject
return self.handler.sendmail(self.uid,to,message.as_string())
def close(self):
self.handler.quit()

Binary file not shown.
Loading…
Cancel
Save