Added Send mail functionality & Dockerized application #1
|
@ -15,4 +15,4 @@ RUN pip install -r requirements.txt
|
||||||
|
|
||||||
# copy project
|
# copy project
|
||||||
COPY . .
|
COPY . .
|
||||||
PeterSurda marked this conversation as resolved
Outdated
|
|||||||
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
|
ENTRYPOINT ["/usr/src/app/entrypoint.sh", "--user"]
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
run as non-root run as non-root
PeterSurda
commented
this doesn't do anything. The this doesn't do anything. The `Dockerfile` should create a non-privileged user and then just before `ENTRYPOINT` have a corresponding `USER` instruction.
|
|
@ -1,7 +1,7 @@
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
web:
|
smtp-gateway:
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
`smtp-gateway:`
|
|||||||
build: .
|
build: .
|
||||||
expose:
|
expose:
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
perhaps this should be inside the perhaps this should be inside the `Dockerfile`
|
|||||||
- "8081"
|
- "8081"
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
If we only use this internally inside a docker service, we should use If we only use this internally inside a docker service, we should use `expose`, not `port`.
|
|||||||
|
|
12
main.py
12
main.py
|
@ -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']
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
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')
|
msg = MIMEText(body, 'plain', 'utf-8')
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
port 587 port 587
|
|||||||
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"]
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
`SERVER_PORT` should default to `587` and be an integer.
|
|||||||
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, "
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
`except KeyError`
|
|||||||
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user
let's call it something else