Added boolean return to functions & added break based on functions response

This commit is contained in:
kuldeep.k@cisinlabs.com 2022-02-25 19:18:37 +05:30
parent f7d6fa0488
commit bd83b01362

18
main.py
View File

@ -32,24 +32,25 @@ class SMTPWebhookApp:
def create_new_client(self, response):
try:
print("- - - - - CREATING CLIENT - - - - -")
mythread.client = smtplib.SMTP(host=SMTP_SERVER_HOST,
port=SMTP_SERVER_PORT)
mythread.client.starttls()
return True
except (smtplib.SMTPException, TimeoutError) as e:
soft_return("can't connect")
response = {"status": 500,
response = {"status": 500, # noqa:F841
"message": "some error: {}".format(e)}
print("response1: ", response)
return False
def smtp_login(self, response, msg):
try:
mythread.client.login(msg["From"], FROM_MAIL_PASSWORD)
return True
except smtplib.SMTPException as e:
soft_return(e)
response = {"status": 500,
response = {"status": 500, # noqa:F841
"message": "some error: {}".format(e)}
print("response2: ", response)
return False
def _send_mail(self):
@ -94,14 +95,15 @@ class SMTPWebhookApp:
if (c == 1):
soft_return("can't connect")
self.create_new_client(response)
self.smtp_login(response, msg)
if not self.create_new_client(response):
break
if not self.smtp_login(response, msg):
break
except smtplib.SMTPException as e:
soft_return("can't send for some reason")
response = {"status": 500,
"message": "some error: {}".format(e)}
print("response3: ", response)
finally:
c += 1