From 1a62a58b38d7bb8b58db82295b750318ee7d6b84 Mon Sep 17 00:00:00 2001 From: fazledyn-or Date: Mon, 23 Oct 2023 12:53:58 +0600 Subject: [PATCH] Added SSL and authentication option for SMTP --- src/scripts/oe_utils.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/scripts/oe_utils.py b/src/scripts/oe_utils.py index 8f92ec0a6..31077e581 100644 --- a/src/scripts/oe_utils.py +++ b/src/scripts/oe_utils.py @@ -94,7 +94,7 @@ def __init__(self, cacheLocation_wmts, cacheLocation_twms, cacheBasename_wmts, c self.emailRecipient = emailRecipient self.emailSender = emailSender -def sigevent_email(type, mssg, smtp_server, recipient, sender): +def sigevent_email(type, mssg, smtp_server, recipient, sender, use_ssl=False, mail_user="", mail_pass=""): """ Send a sigevent message via email. Arguments: @@ -135,9 +135,18 @@ def sigevent_email(type, mssg, smtp_server, recipient, sender): msg['From'] = sender msg['To'] = recipient try: - s = smtplib.SMTP(smtp_server) - s.sendmail(sender, recipient.replace(",",";").split(";"), msg.as_string()) - s.quit() + if use_ssl: + s = smtplib.SMTP_SSL(smtp_server) + if mail_user != "" and mail_pass != "": + s.login(mail_user, mail_pass) + s.sendmail(sender, recipient.replace(",",";").split(";"), msg.as_string()) + s.quit() + else: + s = smtplib.SMTP(smtp_server) + if mail_user != "" and mail_pass != "": + s.login(mail_user, mail_pass) + s.sendmail(sender, recipient.replace(",",";").split(";"), msg.as_string()) + s.quit() except Exception as e: log_info_mssg("ERROR: Cannot send email using SMTP server " + smtp_server + ", " + str(e))