revert Refactor email configuration handling and improve logging for email delivery
This commit is contained in:
2026-09-16 15:37:12 +00:00
parent aa9eb4996a
commit 5d908b6142
3 changed files with 12 additions and 33 deletions
+5 -17
View File
@@ -220,25 +220,13 @@ SSL_CERT = _get(_conf, ['ssl', 'cert'], DEFAULTS['ssl']['cert'])
SSL_KEY = _get(_conf, ['ssl', 'key'], DEFAULTS['ssl']['key'])
# Email settings
def _get_email_env(name, default=''):
value = os.getenv(name)
if value is None:
return default
value = value.strip()
return '' if value.lower() in {'', 'false', 'none', 'null'} else value
EMAIL_ENABLED = _get_email_env('EMAIL_ENABLED').lower() in {'1', 'true', 'yes', 'on'}
EMAIL_SMTP_HOST = _get_email_env('EMAIL_SMTP_HOST')
EMAIL_ENABLED = bool(os.getenv('EMAIL_ENABLED', False))
EMAIL_SMTP_HOST = str(os.getenv('EMAIL_SMTP_HOST', False))
EMAIL_SMTP_PORT = int(os.getenv('EMAIL_SMTP_PORT', 587))
EMAIL_USE_TLS = True
EMAIL_USERNAME = _get_email_env('EMAIL_USERNAME')
EMAIL_PASSWORD = _get_email_env('EMAIL_PASSWORD')
EMAIL_FROM_ADDRESS = (
_get_email_env('EMAIL_FROM_ADDRESS')
or _get(_conf, ['email', 'from_address'], '')
or EMAIL_USERNAME
)
EMAIL_USERNAME = str(os.getenv('EMAIL_USERNAME', False))
EMAIL_PASSWORD = str(os.getenv('EMAIL_PASSWORD', False))
EMAIL_FROM_ADDRESS = _get(_conf, ['email', 'from_address'], EMAIL_USERNAME)
EMAIL_DEFAULT_SENDER_NAME = "Invario Inventarsystem Sender"
EMAIL_TIMEOUT_SECONDS = 20
+2 -10
View File
@@ -3,18 +3,11 @@ from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
import smtplib
import time
import logging
import Web.modules.database.settings as cfg
logger = logging.getLogger(__name__)
def _build_smtp_client():
if not cfg.EMAIL_SMTP_HOST:
raise RuntimeError('EMAIL_SMTP_HOST ist nicht konfiguriert')
smtp = smtplib.SMTP(
cfg.EMAIL_SMTP_HOST,
cfg.EMAIL_SMTP_PORT,
@@ -38,12 +31,11 @@ def _normalize_recipients(email: list | str) -> list[str]:
def _send_message(email: list | str, subject: str, note: str, sender: str, attachment=None) -> bool:
"""Send a plain/HTML message, optionally with one PDF attachment."""
if not cfg.MODULES.is_enabled("mail"):
logger.info("Email delivery skipped because the mail module is disabled")
print("Debug: Module not enabled")
return False
recipients = _normalize_recipients(email)
if not recipients:
logger.warning("Email delivery skipped because no recipients were provided")
return False
body_message = note
@@ -112,7 +104,7 @@ def _send_message(email: list | str, subject: str, note: str, sender: str, attac
return True
except Exception as e:
logger.exception("Email delivery failed: %s", e)
print(f"Debug: Fehler beim Senden der E-Mail: {e}")
return False
finally:
if smtp: