11#!/usr/local/bin/python3
22
3- # version 1.0.6 .0
3+ # version 1.0.7 .0
44
55########################
66# Emergency mail CONFIG - when some error occures
4545
4646
4747class EmailClient (object ):
48- def __init__ (self , server , port , login , password , use_tls , sender , recipient ):
48+ def __init__ (self , server , port , login , password , use_tls , use_ssl , sender , recipient ):
4949 self ._server = server
5050 self ._port = port
5151 self ._login = login
5252 self ._password = password
5353 self ._use_tls = use_tls
5454 self ._sender = sender
5555 self ._recipient = recipient
56+ self ._use_ssl = use_ssl
5657
5758 def send_email (self , subject , message ):
5859 sender = self ._sender
@@ -67,9 +68,16 @@ def send_email(self, subject, message):
6768 msg ["X-Mailer" ] = XMAILER_NAME
6869
6970 try :
70- smtp = smtplib .SMTP (self ._server , self ._port , timeout = 30 )
71+ if self ._use_ssl :
72+ smtp = smtplib .SMTP_SSL (self ._server , self ._port , timeout = 30 )
73+ smtp .ehlo ()
74+ my_logger .info ("using ssl" )
75+ else :
76+ smtp = smtplib .SMTP (self ._server , self ._port , timeout = 30 )
77+
7178 if self ._use_tls :
7279 smtp .starttls ()
80+ my_logger .info ("using tls" )
7381 if self ._login and self ._password :
7482 smtp .login (str (self ._login ), str (self ._password ))
7583 smtp .sendmail (sender , [recipient ], msg .as_string ())
@@ -90,6 +98,7 @@ def __init__(self):
9098 self .subject = ""
9199 self .mbody = ""
92100 self .useTls = False
101+ self .useSSL = False
93102
94103
95104class cNotification :
@@ -205,14 +214,18 @@ def read_and_parse_config_file(self, config_file_path):
205214 config_file_content = config_file .read ()
206215 config = json .loads (config_file_content .encode ().decode ('utf-8-sig' ))
207216 self .mail .host = config ["notification" ]["mail" ]["host" ]
208- if 'port' in config ["notification" ]["mail" ]:
209- self .mail .port = config ["notification" ]["mail" ]["port" ]
210217 self .mail .user = config ["notification" ]["mail" ]["user" ]
211218 self .mail .password = config ["notification" ]["mail" ]["password" ]
212219 self .mail .sender = config ["notification" ]["mail" ]["from" ]
213220 self .mail .recipient = config ["notification" ]["mail" ]["to" ]
214221 if 'use_tls' in config ["notification" ]["mail" ]:
215222 self .mail .useTls = config ["notification" ]["mail" ]["use_tls" ]
223+ if 'use_ssl' in config ["notification" ]["mail" ]:
224+ self .mail .useSSL = config ["notification" ]["mail" ]["use_ssl" ]
225+ self .mail .useTls = False
226+ self .mail .port = 465
227+ if 'port' in config ["notification" ]["mail" ]:
228+ self .mail .port = config ["notification" ]["mail" ]["port" ]
216229 self .notification .host = config ["notification" ]["push_notification" ]["host" ]
217230 self .notification .path = config ["notification" ]["push_notification" ]["path" ]
218231 self .notification .appToken = config ["notification" ]["push_notification" ]["app_token" ]
@@ -240,7 +253,7 @@ def read_and_parse_config_file(self, config_file_path):
240253 quit (0 )
241254
242255 def processFiles (self , files , dataset ):
243-
256+
244257 try :
245258 pattern = re .compile (dataset .regexRow )
246259 except :
@@ -372,6 +385,7 @@ def send_pushnotification(text, host, path, token, key, priority, title):
372385 my_logger .addHandler (handler )
373386
374387 try :
388+
375389 with open (LAST_LINES_FILE_PATH , "x" , encoding = "utf-8" ) as file :
376390 file .write ("{}" )
377391 except :
@@ -389,7 +403,7 @@ def send_pushnotification(text, host, path, token, key, priority, title):
389403 my_logger .info ("push notification sent" )
390404
391405 if len (logMonitor .mail .mbody ) > 0 :
392- email = EmailClient (logMonitor .mail .host , logMonitor .mail .port , logMonitor .mail .user , logMonitor .mail .password , logMonitor .mail .useTls , logMonitor .mail .sender , logMonitor .mail .recipient )
406+ email = EmailClient (logMonitor .mail .host , logMonitor .mail .port , logMonitor .mail .user , logMonitor .mail .password , logMonitor .mail .useTls , logMonitor .mail .useSSL , logMonitor . mail . sender , logMonitor .mail .recipient )
393407 if email .send_email (logMonitor .mail .subject , logMonitor .mail .mbody ):
394408 logMonitor .offsets .remove_old_and_save (logMonitor .processed_files )
395409 else :
0 commit comments