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
3 changed files with 7 additions and 9 deletions
Showing only changes of commit 44df0eed25 - Show all commits

View File

@ -15,4 +15,4 @@ RUN pip install -r requirements.txt
# copy project # copy project
COPY . . COPY . .
ENTRYPOINT ["/usr/src/app/entrypoint.sh"] ENTRYPOINT ["/usr/src/app/entrypoint.sh", "--user"]

View File

@ -1,7 +1,7 @@
version: '3.8' version: '3.8'
services: services:
web: smtp-gateway:
build: . build: .
expose: expose:
- "8081" - "8081"

12
main.py
View File

@ -25,7 +25,7 @@ class SMTPWebhookApp:
req_body = json.loads(rawbody) req_body = json.loads(rawbody)
subject = req_body['subject'] subject = req_body['subject']
body = req_body['body'] body = req_body['body']
client = smtplib.SMTP(SERVER_NAME) client = smtplib.SMTP(host=SERVER_HOST, port=SERVER_PORT)
msg = MIMEText(body, 'plain', 'utf-8') msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8') msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = FROM_MAIL msg['From'] = FROM_MAIL
@ -53,16 +53,14 @@ ROOT = SMTPWebhookApp()
if __name__ == "__main__": if __name__ == "__main__":
try: try:
SERVER_NAME = os.environ["server_name"] SERVER_HOST = os.environ["server_host"]
SERVER_PORT = os.environ["server_port"]
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"]
# to_mail = "test111@mailinator.com"
# from_mail = "test@gmail.com"
# from_mail_password = "test@123"
except KeyError: except KeyError:
raise "Please check missing environment variables: to_mail, from_mail, \ raise KeyError("Please check missing environment variables: to_mail, "
from_mail_password" "from_mail, from_mail_password")
cherrypy.server.socket_host = "0.0.0.0" cherrypy.server.socket_host = "0.0.0.0"
cherrypy.server.socket_port = 8081 cherrypy.server.socket_port = 8081