From c7a36d2ebef3e115e19e69f2c8b128505caa4e45 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 23 Jun 2024 16:24:52 +0200 Subject: [PATCH] feat(email): add email configuration support Configured email backend to use SMTP, console, or file-based backends based on settings. Added fallback values to handle various configurations. Updated `.gitignore` to exclude email files. This enhances email handling capabilities and ensures configuration flexibility. --- .gitignore | 3 ++- freedoi/settings.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9de8853..fb1a1c2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ static/js/* media/ .venv/ venv/ -/static/ \ No newline at end of file +/static/ +/emails/ \ No newline at end of file diff --git a/freedoi/settings.py b/freedoi/settings.py index 5eb7bf5..fc1b67e 100644 --- a/freedoi/settings.py +++ b/freedoi/settings.py @@ -168,3 +168,22 @@ REST_FRAMEWORK = { "rest_framework.permissions.IsAuthenticated", ], } + +# Mail + +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" + +if (email_host := CONFIG.get("Email", "Host", fallback=None)) is not None: + EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" + EMAIL_HOST = email_host + EMAIL_PORT = CONFIG.getint("Email", "Port", fallback=25) + EMAIL_USE_TLS = CONFIG.getboolean("Email", "TLS", fallback=False) + EMAIL_USE_SSL = CONFIG.getboolean("Email", "SSL", fallback=False) + EMAIL_HOST_USER = CONFIG.get("Email", "Username") + EMAIL_HOST_PASSWORD = CONFIG.get("Email", "Password") + +else: + EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend" + EMAIL_FILE_PATH = "emails" + +EMAIL_SUBJECT_PREFIX = "[FreeDOI] " \ No newline at end of file