Added boolean return to functions & added break based on functions response
This commit is contained in:
parent
f7d6fa0488
commit
bd83b01362
18
main.py
18
main.py
|
@ -32,24 +32,25 @@ class SMTPWebhookApp:
|
||||||
|
|
||||||
def create_new_client(self, response):
|
def create_new_client(self, response):
|
||||||
try:
|
try:
|
||||||
print("- - - - - CREATING CLIENT - - - - -")
|
|
||||||
mythread.client = smtplib.SMTP(host=SMTP_SERVER_HOST,
|
mythread.client = smtplib.SMTP(host=SMTP_SERVER_HOST,
|
||||||
port=SMTP_SERVER_PORT)
|
port=SMTP_SERVER_PORT)
|
||||||
mythread.client.starttls()
|
mythread.client.starttls()
|
||||||
|
return True
|
||||||
except (smtplib.SMTPException, TimeoutError) as e:
|
except (smtplib.SMTPException, TimeoutError) as e:
|
||||||
soft_return("can't connect")
|
soft_return("can't connect")
|
||||||
response = {"status": 500,
|
response = {"status": 500, # noqa:F841
|
||||||
"message": "some error: {}".format(e)}
|
"message": "some error: {}".format(e)}
|
||||||
print("response1: ", response)
|
return False
|
||||||
|
|
||||||
def smtp_login(self, response, msg):
|
def smtp_login(self, response, msg):
|
||||||
try:
|
try:
|
||||||
mythread.client.login(msg["From"], FROM_MAIL_PASSWORD)
|
mythread.client.login(msg["From"], FROM_MAIL_PASSWORD)
|
||||||
|
return True
|
||||||
except smtplib.SMTPException as e:
|
except smtplib.SMTPException as e:
|
||||||
soft_return(e)
|
soft_return(e)
|
||||||
response = {"status": 500,
|
response = {"status": 500, # noqa:F841
|
||||||
"message": "some error: {}".format(e)}
|
"message": "some error: {}".format(e)}
|
||||||
print("response2: ", response)
|
return False
|
||||||
|
|
||||||
def _send_mail(self):
|
def _send_mail(self):
|
||||||
|
|
||||||
|
@ -94,14 +95,15 @@ class SMTPWebhookApp:
|
||||||
if (c == 1):
|
if (c == 1):
|
||||||
soft_return("can't connect")
|
soft_return("can't connect")
|
||||||
|
|
||||||
self.create_new_client(response)
|
if not self.create_new_client(response):
|
||||||
self.smtp_login(response, msg)
|
break
|
||||||
|
if not self.smtp_login(response, msg):
|
||||||
|
break
|
||||||
|
|
||||||
except smtplib.SMTPException as e:
|
except smtplib.SMTPException as e:
|
||||||
soft_return("can't send for some reason")
|
soft_return("can't send for some reason")
|
||||||
response = {"status": 500,
|
response = {"status": 500,
|
||||||
"message": "some error: {}".format(e)}
|
"message": "some error: {}".format(e)}
|
||||||
print("response3: ", response)
|
|
||||||
finally:
|
finally:
|
||||||
c += 1
|
c += 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user