diff --git a/.gitignore b/.gitignore index b8c1418b..f9246864 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ nginx/config/* config.production.json ghost/data/* !ghost/data/.gitkeep -api/nvdnew/settings/mail_settings.py .DS_Store +postfix/.env \ No newline at end of file diff --git a/api/nvdnew/settings/mail_settings.py b/api/nvdnew/settings/mail_settings.py new file mode 100644 index 00000000..02e5bd8a --- /dev/null +++ b/api/nvdnew/settings/mail_settings.py @@ -0,0 +1,16 @@ +EMAIL_HOST = 'postfix' + +EMAIL_HOST_USER = '' + +EMAIL_HOST_PASSWORD = '' + +# Normally using port 25 is unsafe as it cannot be encrypted. +# However, all the traffic to port 25 will remain inside docker. +# After the traffic leaves docker through the mailserver, it will be on port 587. +EMAIL_PORT = '25' + +EMAIL_USE_TLS = False + +EMAIL_USE_SSL = False + +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' \ No newline at end of file diff --git a/api/nvdnew/settings/mail_settings_default.py b/api/nvdnew/settings/mail_settings_default.py deleted file mode 100644 index 6d3299cf..00000000 --- a/api/nvdnew/settings/mail_settings_default.py +++ /dev/null @@ -1,13 +0,0 @@ -EMAIL_HOST = 'mail.uniweb.no' - -EMAIL_HOST_USER = 'do-not-reply@nettverksdagene.no' - -EMAIL_HOST_PASSWORD = '' - -EMAIL_PORT = '587' - -EMAIL_USE_TLS = True - -EMAIL_USE_SSL = False - -EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' \ No newline at end of file diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index 1f9ad239..11c10483 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -57,5 +57,17 @@ services: - ./nginx/config:/config # Todo: Can this volume include the below? - frontend-files:/frontend + postfix: + build: + context: ./postfix + ports: + - "587:587" + env_file: + - path: ./postfix/.env + required: true + volumes: + - postfix-spool:/var/spool/postfix # Volume for storing unset postfix emails + volumes: frontend-files: + postfix-spool: \ No newline at end of file diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 1f9ad239..07d28df7 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -57,5 +57,19 @@ services: - ./nginx/config:/config # Todo: Can this volume include the below? - frontend-files:/frontend + # Is postfix nessesary for tests? Do we actually use the tests? Do the tests even work? + # These are all good questions that I don't have the answer to and I'm too annoyed of this project to find out. + # I have included it here because why not. + postfix: + build: + context: ./postfix + ports: + - "587:587" + env_file: + - path: ./postfix/.env.default + required: true + - path: ./postfix/.env + required: false + volumes: frontend-files: diff --git a/docker-compose.yml b/docker-compose.yml index e186e0e5..1bbd0bdf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: - DJANGO_SETTINGS_MODULE=nvdnew.settings.dev depends_on: - postgres + frontend: build: context: ./frontend @@ -30,6 +31,7 @@ services: - ./frontend/src:/frontend/src - ./frontend/static:/frontend/static - ./frontend/test:/frontend/test + fileserver: build: ./fileserver ports: @@ -37,3 +39,14 @@ services: command: ["./main"] volumes: - ./fileserver/uploads:/root/uploads + + postfix: + build: + context: ./postfix + ports: + - "587:587" + env_file: + - path: ./postfix/.env.default + required: true + - path: ./postfix/.env + required: false \ No newline at end of file diff --git a/postfix/.env.default b/postfix/.env.default new file mode 100644 index 00000000..f567354a --- /dev/null +++ b/postfix/.env.default @@ -0,0 +1,8 @@ +# This is only included as an example. +# You should create your own .env file with real values for prod! + +SMTP_SERVER=smtp.some-provier.com +SMTP_PORT=587 +SMTP_USERNAME=the username for the smtp server +SMTP_PASSWORD=a very secure password +SERVER_HOSTNAME=nettverksdagene.no \ No newline at end of file diff --git a/postfix/Dockerfile b/postfix/Dockerfile new file mode 100644 index 00000000..42f1be8f --- /dev/null +++ b/postfix/Dockerfile @@ -0,0 +1,6 @@ +FROM juanluisbaptiste/postfix:latest + +# Add a delay between every email sent +# Needed to avoid hitting the rate limit +# A bit hacky but it works :) +RUN echo -e "\ndefault_destination_rate_delay = 3s\n" >> /etc/postfix/main.cf \ No newline at end of file