smtp-handling #3

Open
PeterSurda wants to merge 3 commits from cis-kuldeep/influx-smtp-gateway:smtp-handling into master
1 changed files with 10 additions and 8 deletions
Showing only changes of commit bd83b01362 - Show all commits

18
main.py
View File

@ -32,24 +32,25 @@ class SMTPWebhookApp:
def create_new_client(self, response):
Review

needs to return a value (e.g. boolean)

needs to return a value (e.g. boolean)
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):
Review

needs to return a value

needs to return a value
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")
Review

need to check for return value and skip login if connect fails

need to check for return value and skip `login` if `connect` fails
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