From 1d51b2a0585e69a6873ced9d625e99e06accf368 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:45:17 +1000 Subject: [PATCH] Email config fix (#5336) (#5338) * Change for DEFAULT_FROM_EMAIL - Use USERNAME if not specified (cherry picked from commit 487ac917c90e9fe3da4effaa9326b707ceecd321) * Email configuration fails if DEFAULT_FROM_EMAIL not set (cherry picked from commit 01e573c3a2702e7c21ed13b0cb44280c89d3dee1) * Docs update (cherry picked from commit bfedb9cf87dbbf8024412afa6454361d45afe967) Co-authored-by: Oliver --- InvenTree/InvenTree/email.py | 14 +++++++++++--- InvenTree/InvenTree/settings.py | 4 ++++ docs/docs/start/config.md | 9 ++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/InvenTree/InvenTree/email.py b/InvenTree/InvenTree/email.py index 20d78a498d..0d2b446a58 100644 --- a/InvenTree/InvenTree/email.py +++ b/InvenTree/InvenTree/email.py @@ -17,6 +17,7 @@ def is_email_configured(): NOTE: This does not check if the configuration is valid! """ configured = True + testing = settings.TESTING if InvenTree.ready.isInTestMode(): return False @@ -28,17 +29,24 @@ def is_email_configured(): configured = False # Display warning unless in test mode - if not settings.TESTING: # pragma: no cover + if not testing: # pragma: no cover logger.debug("EMAIL_HOST is not configured") # Display warning unless in test mode - if not settings.EMAIL_HOST_USER and not settings.TESTING: # pragma: no cover + if not settings.EMAIL_HOST_USER and not testing: # pragma: no cover logger.debug("EMAIL_HOST_USER is not configured") # Display warning unless in test mode - if not settings.EMAIL_HOST_PASSWORD and not settings.TESTING: # pragma: no cover + if not settings.EMAIL_HOST_PASSWORD and testing: # pragma: no cover logger.debug("EMAIL_HOST_PASSWORD is not configured") + # Email sender must be configured + if not settings.DEFAULT_FROM_EMAIL: + configured = False + + if not testing: # pragma: no cover + logger.warning("DEFAULT_FROM_EMAIL is not configured") + return configured diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index cb19ddef7a..f8244dfe91 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -822,6 +822,10 @@ EMAIL_USE_SSL = get_boolean_setting('INVENTREE_EMAIL_SSL', 'email.ssl', False) DEFAULT_FROM_EMAIL = get_setting('INVENTREE_EMAIL_SENDER', 'email.sender', '') +# If "from" email not specified, default to the username +if not DEFAULT_FROM_EMAIL: + DEFAULT_FROM_EMAIL = get_setting('INVENTREE_EMAIL_USERNAME', 'email.username', '') + EMAIL_USE_LOCALTIME = False EMAIL_TIMEOUT = 60 diff --git a/docs/docs/start/config.md b/docs/docs/start/config.md index 52b0fec408..a0176970c1 100644 --- a/docs/docs/start/config.md +++ b/docs/docs/start/config.md @@ -155,9 +155,16 @@ The following email settings are available: | INVENTREE_EMAIL_PASSWORD | email.password | Email account password | *Not specified* | | INVENTREE_EMAIL_TLS | email.tls | Enable TLS support | False | | INVENTREE_EMAIL_SSL | email.ssl | Enable SSL support | False | -| INVENTREE_EMAIL_SENDER | email.sender | Name of sender | *Not specified* | +| INVENTREE_EMAIL_SENDER | email.sender | Sending email address | *Not specified* | | INVENTREE_EMAIL_PREFIX | email.prefix | Prefix for subject text | [InvenTree] | +### Sender Email + +The "sender" email address is the address from which InvenTree emails are sent (by default) and must be specified for outgoing emails to function: + +!!! info "Fallback" + If `INVENTREE_EMAIL_SENDER` is not provided, the system will fall back to `INVENTREE_EMAIL_USERNAME` (if the username is a valid email address) + ## Supported Currencies The currencies supported by InvenTree must be specified in the [configuration file](#configuration-file).