diff --git a/InvenTree/InvenTree/context.py b/InvenTree/InvenTree/context.py index 3e9af2f751..e072f5a5ea 100644 --- a/InvenTree/InvenTree/context.py +++ b/InvenTree/InvenTree/context.py @@ -32,6 +32,7 @@ def health_status(request): status = { 'django_q_running': InvenTree.status.is_worker_running(), + 'email_configured': InvenTree.status.is_email_configured(), } all_healthy = True diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index fd57167dd4..5ee79753ca 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -498,7 +498,10 @@ 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 = get_setting( + 'django.core.mail.backends.smtp.EmailBackend', + email_config.get('backend', '') +) # Email backend settings EMAIL_HOST = get_setting( diff --git a/InvenTree/InvenTree/status.py b/InvenTree/InvenTree/status.py index 88acc69a7a..e9846e445a 100644 --- a/InvenTree/InvenTree/status.py +++ b/InvenTree/InvenTree/status.py @@ -11,6 +11,9 @@ from datetime import datetime, timedelta from django_q.models import Success from django_q.monitor import Stat +from django.conf import settings + + logger = logging.getLogger("inventree") @@ -43,6 +46,30 @@ def is_worker_running(**kwargs): return results.exists() +def is_email_configured(): + """ + Check if email backend is configured. + + NOTE: This does not check if the configuration is valid! + """ + + configured = True + + if not settings.EMAIL_HOST: + logger.warning("EMAIL_HOST is not configured") + configured = False + + if not settings.EMAIL_HOST_USER: + logger.warning("EMAIL_HOST_USER is not configured") + configured = False + + if not settings.EMAIL_HOST_PASSWORD: + logger.warning("EMAIL_HOST_PASSWORD is not configured") + configured = False + + return configured + + def check_system_health(**kwargs): """ Check that the InvenTree system is running OK. @@ -56,6 +83,10 @@ def check_system_health(**kwargs): result = False logger.warning(_("Background worker check failed")) + if not is_email_configured(): + result = False + logger.warning(_("Email backend not configured")) + if not result: logger.warning(_("InvenTree system health checks failed")) diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 506788a5f1..81411dee55 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -74,7 +74,9 @@ currencies: # tls: Enable TLS support # ssl: Enable SSL support -# Alternatively, these options can all be set using environment variables +# Alternatively, these options can all be set using environment variables, +# with the INVENTREE_EMAIL_ prefix: +# e.g. INVENTREE_EMAIL_HOST / INVENTREE_EMAIL_PORT / INVENTREE_EMAIL_USERNAME # Refer to the InvenTree documentation for more information email: diff --git a/InvenTree/templates/registration/login.html b/InvenTree/templates/registration/login.html index 746d3c86fa..37eda9a103 100644 --- a/InvenTree/templates/registration/login.html +++ b/InvenTree/templates/registration/login.html @@ -89,9 +89,12 @@ + + {% if email_configured %}
{% trans "Forgotten your password?" %} - {% trans "Click here to reset" %}
+ {% endif %} diff --git a/InvenTree/templates/stats.html b/InvenTree/templates/stats.html index 30d3f3d881..eff9c4504f 100644 --- a/InvenTree/templates/stats.html +++ b/InvenTree/templates/stats.html @@ -25,18 +25,29 @@ {% endif %} + {% if not django_q_running %}