Updated docker-compose entrypoint to run as entrypoint, server_port for smtp function and exception handling update
buildbot/travis_bionic Build done. Details

This commit is contained in:
kuldeep.k@cisinlabs.com 2022-02-10 21:16:00 +05:30
parent 8488446e37
commit 44df0eed25
3 changed files with 7 additions and 9 deletions

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