From bd9f68bb27d8b5054a1b6ba9fd23370b8875ef31 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sun, 8 Oct 2023 22:19:54 +1100 Subject: [PATCH] =?UTF-8?q?Notification=20rework=20-=20SMTP=20v0.3=20-=20W?= =?UTF-8?q?IP=F0=9F=91=B7=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/plugins/_publisher_email/config.json | 2 +- .../_publisher_email/{email.py => email_smtp.py} | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) rename front/plugins/_publisher_email/{email.py => email_smtp.py} (89%) diff --git a/front/plugins/_publisher_email/config.json b/front/plugins/_publisher_email/config.json index b1e62b03..bc867b7e 100755 --- a/front/plugins/_publisher_email/config.json +++ b/front/plugins/_publisher_email/config.json @@ -348,7 +348,7 @@ { "function": "CMD", "type": "readonly", - "default_value": "python3 /home/pi/pialert/front/plugins/_publisher_email/email.py", + "default_value": "python3 /home/pi/pialert/front/plugins/_publisher_email/email_smtp.py", "options": [], "localized": [ "name", diff --git a/front/plugins/_publisher_email/email.py b/front/plugins/_publisher_email/email_smtp.py similarity index 89% rename from front/plugins/_publisher_email/email.py rename to front/plugins/_publisher_email/email_smtp.py index 25f1d638..dfb2d379 100755 --- a/front/plugins/_publisher_email/email.py +++ b/front/plugins/_publisher_email/email_smtp.py @@ -72,8 +72,8 @@ def main(): #------------------------------------------------------------------------------- def check_config (): - if get_setting_value('SMTP_SERVER') == '' or get_setting_value('REPORT_FROM') == '' or get_setting_value('REPORT_TO') == '': - mylog('none', ['[Email Check Config] Error: Email service not set up correctly. Check your pialert.conf SMTP_*, REPORT_FROM and REPORT_TO variables.']) + if get_setting_value('SMTP_SERVER') == '' or get_setting_value('SMTP_REPORT_FROM') == '' or get_setting_value('SMTP_REPORT_TO') == '': + mylog('none', ['[Email Check Config] Error: Email service not set up correctly. Check your pialert.conf SMTP_*, SMTP_REPORT_FROM and SMTP_REPORT_TO variables.']) return False else: return True @@ -81,13 +81,13 @@ def check_config (): #------------------------------------------------------------------------------- def send(pHTML, pText): - mylog('debug', [f'[{pluginName}] REPORT_TO: {hide_email(str(get_setting_value('REPORT_TO')))} SMTP_USER: {hide_email(str(get_setting_value('SMTP_USER')))}']) + mylog('debug', [f'[{pluginName}] SMTP_REPORT_TO: {hide_email(str(get_setting_value("SMTP_REPORT_TO")))} SMTP_USER: {hide_email(str(get_setting_value("SMTP_USER")))}']) # Compose email msg = MIMEMultipart('alternative') msg['Subject'] = 'Pi.Alert Report' - msg['From'] = get_setting_value('REPORT_FROM') - msg['To'] = get_setting_value('REPORT_TO') + msg['From'] = get_setting_value('SMTP_REPORT_FROM') + msg['To'] = get_setting_value('SMTP_REPORT_TO') msg.attach (MIMEText (pText, 'plain')) msg.attach (MIMEText (pHTML, 'html')) @@ -135,11 +135,11 @@ def send(pHTML, pText): failedAt = print_log('SMTP_SKIP_TLS == False so sending .ehlo()') smtp_connection.ehlo() if not get_setting_value('SMTP_SKIP_LOGIN'): - failedAt = print_log('SMTP_SKIP_LOGIN') == False so sending .login()') + failedAt = print_log('SMTP_SKIP_LOGIN == False so sending .login()') smtp_connection.login (get_setting_value('SMTP_USER'), get_setting_value('SMTP_PASS')) failedAt = print_log('Sending .sendmail()') - smtp_connection.sendmail (get_setting_value('REPORT_FROM'), get_setting_value('REPORT_TO'), msg.as_string()) + smtp_connection.sendmail (get_setting_value('SMTP_REPORT_FROM'), get_setting_value('SMTP_REPORT_TO'), msg.as_string()) smtp_connection.quit() except smtplib.SMTPAuthenticationError as e: mylog('none', [' ERROR: Failed at - ', failedAt])