Added Send mail functionality & Dockerized application #1

Merged
PeterSurda merged 11 commits from cis-kuldeep/influx-smtp-gateway:master into master 2022-02-21 06:41:14 +00:00
1 changed files with 4 additions and 21 deletions
Showing only changes of commit 5881dc7b1a - Show all commits

25
main.py
View File

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

change docstring

change docstring
"""
import configparser
import os
import json
import smtplib
import socket
import sys
from email.header import Header
from email.mime.text import MIMEText
@ -61,31 +59,16 @@ if __name__ == "__main__":
TO_MAIL = os.environ["to_mail"]
FROM_MAIL = os.environ["from_mail"]
FROM_MAIL_PASSWORD = os.environ["from_mail_password"]
except:
raise "Please check missing environment variables: to_mail, from_mail, from_mail_password"
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"
cherrypy.server.socket_host = SERVER_HOST
cherrypy.server.socket_port = SERVER_PORT
PeterSurda marked this conversation as resolved Outdated

except smtplib.SMTPException

`except smtplib.SMTPException`
ENGINE = cherrypy.engine
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
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)
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:
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