From 2fed1888626a4cbaaa19f4df2497e51cd0fbea01 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 5 Jan 2022 17:35:42 -0800 Subject: [PATCH] Configure email sender from .env file --- .env.dev.example | 3 +++ .env.prod.example | 3 +++ bookwyrm/emailing.py | 2 +- bookwyrm/settings.py | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.env.dev.example b/.env.dev.example index 22e12de12..4a2cac261 100644 --- a/.env.dev.example +++ b/.env.dev.example @@ -42,6 +42,9 @@ EMAIL_HOST_USER=mail@your.domain.here EMAIL_HOST_PASSWORD=emailpassword123 EMAIL_USE_TLS=true EMAIL_USE_SSL=false +EMAIL_SENDER_NAME=admin +# defaults to DOMAIN +EMAIL_SENDER_DOMAIN= # Thumbnails Generation ENABLE_THUMBNAIL_GENERATION=false diff --git a/.env.prod.example b/.env.prod.example index 2e0ced5e8..e016839fd 100644 --- a/.env.prod.example +++ b/.env.prod.example @@ -42,6 +42,9 @@ EMAIL_HOST_USER=mail@your.domain.here EMAIL_HOST_PASSWORD=emailpassword123 EMAIL_USE_TLS=true EMAIL_USE_SSL=false +EMAIL_SENDER_NAME=admin +# defaults to DOMAIN +EMAIL_SENDER_DOMAIN= # Thumbnails Generation ENABLE_THUMBNAIL_GENERATION=false diff --git a/bookwyrm/emailing.py b/bookwyrm/emailing.py index 08fd9ef85..efef12638 100644 --- a/bookwyrm/emailing.py +++ b/bookwyrm/emailing.py @@ -69,7 +69,7 @@ def format_email(email_name, data): def send_email(recipient, subject, html_content, text_content): """use a task to send the email""" email = EmailMultiAlternatives( - subject, text_content, settings.DEFAULT_FROM_EMAIL, [recipient] + subject, text_content, settings.EMAIL_SENDER, [recipient] ) email.attach_alternative(html_content, "text/html") email.send() diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index f2068a16b..d7f4a5050 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -24,7 +24,9 @@ EMAIL_HOST_USER = env("EMAIL_HOST_USER") EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD") EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True) EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", False) -DEFAULT_FROM_EMAIL = f"admin@{DOMAIN}" +EMAIL_SENDER_NAME = env.bool("EMAIL_SENDER_NAME", "admin") +EMAIL_SENDER_DOMAIN = env.bool("EMAIL_SENDER_NAME", DOMAIN) +EMAIL_SENDER = f"{EMAIL_SENDER_NAME}@{EMAIL_SENDER_DOMAIN}" # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))