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
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 . .
PeterSurda marked this conversation as resolved Outdated

let's call it something else

let's call it something else
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
ENTRYPOINT ["/usr/src/app/entrypoint.sh", "--user"]
PeterSurda marked this conversation as resolved Outdated

run as non-root

run as non-root

this doesn't do anything. The Dockerfile should create a non-privileged user and then just before ENTRYPOINT have a corresponding USER instruction.

this doesn't do anything. The `Dockerfile` should create a non-privileged user and then just before `ENTRYPOINT` have a corresponding `USER` instruction.

View File

@ -1,7 +1,7 @@
version: '3.8'
services:
web:
smtp-gateway:
PeterSurda marked this conversation as resolved Outdated

smtp-gateway:

`smtp-gateway:`
build: .
expose:
PeterSurda marked this conversation as resolved Outdated

perhaps this should be inside the Dockerfile

perhaps this should be inside the `Dockerfile`
- "8081"
PeterSurda marked this conversation as resolved Outdated

If we only use this internally inside a docker service, we should use expose, not port.

If we only use this internally inside a docker service, we should use `expose`, not `port`.

12
main.py
View File

@ -25,7 +25,7 @@ class SMTPWebhookApp:
req_body = json.loads(rawbody)
subject = req_body['subject']
body = req_body['body']
PeterSurda marked this conversation as resolved Outdated

debug we don't need

debug we don't need
client = smtplib.SMTP(SERVER_NAME)
client = smtplib.SMTP(host=SERVER_HOST, port=SERVER_PORT)
msg = MIMEText(body, 'plain', 'utf-8')
PeterSurda marked this conversation as resolved Outdated

port 587

port 587
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = FROM_MAIL
@ -53,16 +53,14 @@ ROOT = SMTPWebhookApp()
if __name__ == "__main__":
try:
SERVER_NAME = os.environ["server_name"]
SERVER_HOST = os.environ["server_host"]
SERVER_PORT = os.environ["server_port"]
PeterSurda marked this conversation as resolved Outdated

SERVER_PORT should default to 587 and be an integer.

`SERVER_PORT` should default to `587` and be an integer.
TO_MAIL = os.environ["to_mail"]
FROM_MAIL = os.environ["from_mail"]
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:
raise "Please check missing environment variables: to_mail, from_mail, \
from_mail_password"
raise KeyError("Please check missing environment variables: to_mail, "
PeterSurda marked this conversation as resolved Outdated

except KeyError

`except KeyError`
"from_mail, from_mail_password")
cherrypy.server.socket_host = "0.0.0.0"
cherrypy.server.socket_port = 8081