mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-14 02:28:23 +00:00
refactor NotificationHelper code
This commit is contained in:
parent
e9e3f17363
commit
96259c53bc
1 changed files with 28 additions and 46 deletions
|
@ -48,54 +48,36 @@ def sendEmailNotification(recipient, term):
|
||||||
if isinstance(sender_pw, tuple):
|
if isinstance(sender_pw, tuple):
|
||||||
sender_pw = sender_pw[0]
|
sender_pw = sender_pw[0]
|
||||||
|
|
||||||
if (
|
# raise an exception if any of these is None
|
||||||
sender is not None and
|
if (sender is None or
|
||||||
sender_host is not None and
|
sender_host is None or
|
||||||
sender_port is not None and
|
sender_port is None
|
||||||
sender_pw is not None
|
|
||||||
):
|
|
||||||
try:
|
|
||||||
|
|
||||||
server_ssl = smtplib.SMTP_SSL(sender_host, sender_port)
|
|
||||||
server_ssl.ehlo()
|
|
||||||
server_ssl.login(sender, sender_pw)
|
|
||||||
|
|
||||||
mime_msg = MIMEMultipart()
|
|
||||||
mime_msg['From'] = sender
|
|
||||||
mime_msg['To'] = recipient
|
|
||||||
mime_msg['Subject'] = "AIL Term Alert"
|
|
||||||
|
|
||||||
body = "New occurrence for term: " + term
|
|
||||||
mime_msg.attach(MIMEText(body, 'plain'))
|
|
||||||
|
|
||||||
server_ssl.sendmail(sender, recipient, mime_msg.as_string())
|
|
||||||
server_ssl.quit()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print str(e)
|
|
||||||
# raise e
|
|
||||||
elif (
|
|
||||||
sender is not None and
|
|
||||||
sender_host is not None and
|
|
||||||
sender_port is not None
|
|
||||||
):
|
):
|
||||||
try:
|
raise Exception('SMTP configuration (host, port, sender) is missing or incomplete!')
|
||||||
|
|
||||||
|
try:
|
||||||
|
if sender_pw is not None:
|
||||||
|
smtp_server = smtplib.SMTP_SSL(sender_host, sender_port)
|
||||||
|
smtp_server.ehlo()
|
||||||
|
smtp_server.login(sender, sender_pw)
|
||||||
|
else:
|
||||||
|
smtp_server = smtplib.SMTP(sender_host, sender_port)
|
||||||
|
|
||||||
|
|
||||||
|
mime_msg = MIMEMultipart()
|
||||||
|
mime_msg['From'] = sender
|
||||||
|
mime_msg['To'] = recipient
|
||||||
|
mime_msg['Subject'] = "AIL Term Alert"
|
||||||
|
|
||||||
|
body = "New occurrence for term: " + term
|
||||||
|
mime_msg.attach(MIMEText(body, 'plain'))
|
||||||
|
|
||||||
|
smtp_server.sendmail(sender, recipient, mime_msg.as_string())
|
||||||
|
smtp_server.quit()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print str(e)
|
||||||
|
# raise e
|
||||||
|
|
||||||
server = smtplib.SMTP(sender_host, sender_port)
|
|
||||||
|
|
||||||
mime_msg = MIMEMultipart()
|
|
||||||
mime_msg['From'] = sender
|
|
||||||
mime_msg['To'] = recipient
|
|
||||||
mime_msg['Subject'] = "AIL Term Alert"
|
|
||||||
|
|
||||||
body = "New occurrence for term: " + term
|
|
||||||
mime_msg.attach(MIMEText(body, 'plain'))
|
|
||||||
|
|
||||||
server.sendmail(sender, recipient, mime_msg.as_string())
|
|
||||||
server.quit()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print str(e)
|
|
||||||
# raise e
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue