Added Send mail functionality & Dockerized application #1

Merged
PeterSurda merged 11 commits from cis-kuldeep/influx-smtp-gateway:master into master 2022-02-21 07:41:14 +01:00
Showing only changes of commit 1d69818718 - Show all commits

View File

@ -14,7 +14,7 @@ from email.mime.text import MIMEText
import cherrypy import cherrypy
import logging import logging
PeterSurda marked this conversation as resolved Outdated

class name

class name
logging.basicConfig(filename='app.log', filemode='w', logging.basicConfig(stream=sys.stdout,
PeterSurda marked this conversation as resolved Outdated

should log to stdout or stderr (research which one is more appropriate)

should log to stdout or stderr (research which one is more appropriate)
format='%(name)s - %(levelname)s - %(message)s') format='%(name)s - %(levelname)s - %(message)s')
PeterSurda marked this conversation as resolved Outdated

docstring

docstring
PeterSurda marked this conversation as resolved
Review

this should go under __main__

this should go under `__main__`
@ -49,7 +49,7 @@ class SMTPWebhookApp:
try: try:
client = smtplib.SMTP(host=SMTP_SERVER_HOST, port=SMTP_SERVER_PORT) client = smtplib.SMTP(host=SMTP_SERVER_HOST, port=SMTP_SERVER_PORT)
except Exception as e: except (smtplib.SMTPConnectionError, TimeoutError) as e:
PeterSurda marked this conversation as resolved Outdated

except (SMTPConnectionError, TimeoutError) as e:

`except (SMTPConnectionError, TimeoutError) as e:`
time.sleep(0.2) time.sleep(0.2)
logging.error("To: {}, error: {}".format(TO_MAIL, e)) logging.error("To: {}, error: {}".format(TO_MAIL, e))
return {"status": 400, "message": "SMTP client error: {}.".format( return {"status": 400, "message": "SMTP client error: {}.".format(
@ -109,6 +109,10 @@ if __name__ == "__main__":
PeterSurda marked this conversation as resolved Outdated

live data shouldn't be here, squash to get rid of it

live data shouldn't be here, squash to get rid of it
cherrypy.tree.mount(ROOT, config={}) cherrypy.tree.mount(ROOT, config={})
if hasattr(ENGINE, "signal_handler"):
ENGINE.signal_handler.subscribe()
if hasattr(ENGINE, "console_control_handler"):
ENGINE.console_control_handler.subscribe()
try: try:
ENGINE.start() ENGINE.start()
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except