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.
This commit is contained in:
Kumi 2024-06-23 16:24:52 +02:00
parent e7a7766351
commit c7a36d2ebe
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 21 additions and 1 deletions

3
.gitignore vendored
View file

@ -7,4 +7,5 @@ static/js/*
media/
.venv/
venv/
/static/
/static/
/emails/

View file

@ -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] "