From 415ec58b9530a5619507da60a3dd272fd1daf1f8 Mon Sep 17 00:00:00 2001 From: Tim Freund Date: Fri, 1 Feb 2019 14:40:24 -0500 Subject: [PATCH] Allow SMTP configuration via environment variables This change allows SMTP configuration via email, but users can still choose to configure the settings directly in local_settings.py --- README.md | 8 +++++++- hc/settings.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5dcc9326..bb9c54e7 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,11 @@ Configurations settings loaded from environment variables: | [DB_CONN_MAX_AGE](https://docs.djangoproject.com/en/2.1/ref/settings/#conn-max-age) | `0` | DB_SSLMODE | `"prefer"` | PostgreSQL-specific, [details](https://blog.github.com/2018-10-21-october21-incident-report/) | DB_TARGET_SESSION_ATTRS | `"read-write"` | PostgreSQL-specific, [details](https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-CONNECT-TARGET-SESSION-ATTRS) +| EMAIL_HOST | `""` *(empty string)* +| EMAIL_PORT | `"587"` +| EMAIL_HOST_USER | `""` *(empty string)* +| EMAIL_HOST_PASSWORD | `""` *(empty string)* +| EMAIL_USE_TLS | `"True"` | SITE_ROOT | `"http://localhost:8000"` | SITE_NAME | `"Mychecks"` | MASTER_BADGE_LABEL | `"Mychecks"` @@ -175,7 +180,8 @@ DATABASES = { ## Sending Emails healthchecks must be able to send email messages, so it can send out login -links and alerts to users. Put your SMTP server configuration in +links and alerts to users. Environment variables can be used to configure +SMTP settings, or your may put your SMTP server configuration in `hc/local_settings.py` like so: ```python diff --git a/hc/settings.py b/hc/settings.py index 3e00d328..52b9038c 100644 --- a/hc/settings.py +++ b/hc/settings.py @@ -158,6 +158,13 @@ COMPRESS_CSS_HASHING_METHOD = "content" DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID") DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET") +# Email integration +EMAIL_HOST = os.getenv("EMAIL_HOST", "") +EMAIL_PORT = envint("EMAIL_PORT", "587") +EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "") +EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "") +EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True") + # Slack integration SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID") SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")