From fb5a94a778b012f508ff6a05267d4aac6da059fd Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 16 Feb 2021 21:30:20 +1100 Subject: [PATCH] Support for email settings --- InvenTree/InvenTree/settings.py | 45 +++++++++++++++++++++++++++++++++ InvenTree/config_template.yaml | 23 +++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 8b5400e374..fd57167dd4 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -495,6 +495,51 @@ CURRENCIES = CONFIG.get( # TODO - Allow live web-based backends in the future EXCHANGE_BACKEND = 'InvenTree.exchange.InvenTreeManualExchangeBackend' +# Extract email settings from the config file +email_config = CONFIG.get('email', {}) + +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' + +# Email backend settings +EMAIL_HOST = get_setting( + 'INVENTREE_EMAIL_HOST', + email_config.get('host', '') +) + +EMAIL_PORT = get_setting( + 'INVENTREE_EMAIL_PORT', + email_config.get('port', 25) +) + +EMAIL_HOST_USER = get_setting( + 'INVENTREE_EMAIL_USERNAME', + email_config.get('username', ''), +) + +EMAIL_HOST_PASSWORD = get_setting( + 'INVENTREE_EMAIL_PASSWORD', + email_config.get('password', ''), +) + +EMAIL_SUBJECT_PREFIX = get_setting( + 'INVENTREE_EMAIL_PREFIX', + email_config.get('prefix', '[InvenTree] '), +) + +EMAIL_USE_LOCALTIME = False + +EMAIL_USE_TLS = get_setting( + 'INVENTREE_EMAIL_TLS', + email_config.get('tls', False), +) + +EMAIL_USE_SSL = get_setting( + 'INVENTREE_EMAIL_SSL', + email_config.get('ssl', False), +) + +EMAIL_TIMEOUT = 60 + LOCALE_PATHS = ( os.path.join(BASE_DIR, 'locale/'), ) diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index a64e6d42c0..506788a5f1 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -63,6 +63,29 @@ currencies: - NZD - USD +# Email backend configuration +# Ref: https://docs.djangoproject.com/en/dev/topics/email/ +# Available options: +# host: Email server host address +# port: Email port +# username: Account username +# password: Account password +# prefix: Email subject prefix +# tls: Enable TLS support +# ssl: Enable SSL support + +# Alternatively, these options can all be set using environment variables +# Refer to the InvenTree documentation for more information + +email: + host: '' + port: 25 + username: '' + password: '' + prefix: '[InvenTree] ' + tls: False + ssl: False + # Set debug to False to run in production mode # Use the environment variable INVENTREE_DEBUG debug: True