mirror of https://github.com/CIRCL/AIL-framework
Merge pull request #191 from drnguyen/master
support non-TLS SMTP servers for email notificationspull/192/head
commit
34a498bcf4
|
@ -47,29 +47,37 @@ def sendEmailNotification(recipient, term):
|
||||||
|
|
||||||
if isinstance(sender_pw, tuple):
|
if isinstance(sender_pw, tuple):
|
||||||
sender_pw = sender_pw[0]
|
sender_pw = sender_pw[0]
|
||||||
|
|
||||||
|
# raise an exception if any of these is None
|
||||||
|
if (sender is None or
|
||||||
|
sender_host is None or
|
||||||
|
sender_port is None
|
||||||
|
):
|
||||||
|
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)
|
||||||
|
|
||||||
if (
|
|
||||||
sender is not None and
|
mime_msg = MIMEMultipart()
|
||||||
sender_host is not None and
|
mime_msg['From'] = sender
|
||||||
sender_port is not None and
|
mime_msg['To'] = recipient
|
||||||
sender_pw is not None
|
mime_msg['Subject'] = "AIL Term Alert"
|
||||||
):
|
|
||||||
try:
|
body = "New occurrence for term: " + term
|
||||||
|
mime_msg.attach(MIMEText(body, 'plain'))
|
||||||
server_ssl = smtplib.SMTP_SSL(sender_host, sender_port)
|
|
||||||
server_ssl.ehlo()
|
smtp_server.sendmail(sender, recipient, mime_msg.as_string())
|
||||||
server_ssl.login(sender, sender_pw)
|
smtp_server.quit()
|
||||||
|
|
||||||
mime_msg = MIMEMultipart()
|
except Exception as e:
|
||||||
mime_msg['From'] = sender
|
print str(e)
|
||||||
mime_msg['To'] = recipient
|
# raise e
|
||||||
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)
|
|
||||||
|
|
|
@ -23,7 +23,9 @@ sentiment_lexicon_file = sentiment/vader_lexicon.zip/vader_lexicon/vader_lexicon
|
||||||
sender = sender@example.com
|
sender = sender@example.com
|
||||||
sender_host = smtp.example.com
|
sender_host = smtp.example.com
|
||||||
sender_port = 1337
|
sender_port = 1337
|
||||||
sender_pw = securepassword
|
|
||||||
|
# optional for using with authenticated SMTP over SSL
|
||||||
|
# sender_pw = securepassword
|
||||||
|
|
||||||
##### Flask #####
|
##### Flask #####
|
||||||
[Flask]
|
[Flask]
|
||||||
|
|
Loading…
Reference in New Issue