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 5881dc7b1a - Show all commits

25
main.py
View File

@ -3,11 +3,9 @@
Serve cloud init files Serve cloud init files
PeterSurda marked this conversation as resolved Outdated

change docstring

change docstring
""" """
import configparser
import os import os
import json import json
import smtplib import smtplib
import socket
import sys import sys
from email.header import Header from email.header import Header
from email.mime.text import MIMEText from email.mime.text import MIMEText
@ -61,31 +59,16 @@ if __name__ == "__main__":
TO_MAIL = os.environ["to_mail"] TO_MAIL = os.environ["to_mail"]
FROM_MAIL = os.environ["from_mail"] FROM_MAIL = os.environ["from_mail"]
FROM_MAIL_PASSWORD = os.environ["from_mail_password"] FROM_MAIL_PASSWORD = os.environ["from_mail_password"]
except: except: # noqa:E722
PeterSurda marked this conversation as resolved Outdated

except KeyError

`except KeyError`
raise "Please check missing environment variables: to_mail, from_mail, from_mail_password" raise "Please check missing environment variables: to_mail, from_mail, \
from_mail_password"
cherrypy.server.socket_host = SERVER_HOST cherrypy.server.socket_host = SERVER_HOST
cherrypy.server.socket_port = SERVER_PORT cherrypy.server.socket_port = SERVER_PORT
PeterSurda marked this conversation as resolved Outdated

except smtplib.SMTPException

`except smtplib.SMTPException`
ENGINE = cherrypy.engine ENGINE = cherrypy.engine
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) cherrypy.tree.mount(ROOT, config={})
CONFIG = {
'/include': {
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(CURRENT_DIR,
'data',
'include'),
'tools.staticdir.content_types': {
'yml': 'text/yaml'
}
}
}
cherrypy.tree.mount(ROOT, config=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()
PeterSurda marked this conversation as resolved Outdated

merge with previous try/except

merge with previous `try`/`except`
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except