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 -6
View File
@@ -253,12 +253,11 @@ jobs:
INVENTAR_SECRET_KEY: ${{secrets.INVENTAR_SECRET_KEY}} INVENTAR_SECRET_KEY: ${{secrets.INVENTAR_SECRET_KEY}}
INVENTAR_DATA_ENCRYPTION_KEY: ${{secrets.INVENTAR_DATA_ENCRYPTION_KEY}} INVENTAR_DATA_ENCRYPTION_KEY: ${{secrets.INVENTAR_DATA_ENCRYPTION_KEY}}
INVENTAR_MONGODB_PASSWORD: ${{secrets.INVENTAR_MONGODB_PASSWORD}} INVENTAR_MONGODB_PASSWORD: ${{secrets.INVENTAR_MONGODB_PASSWORD}}
EMAIL_ENABLED: "${{ secrets.EMAIL_ENABLED }}" EMAIL_ENABLED: ${{secrets.EMAIL_ENABLED}}
EMAIL_SMTP_HOST: "${{ secrets.EMAIL_SMTP_HOST }}" EMAIL_SMTP_HOST: ${{secrets.EMAIL_SMTP_HOST}}
EMAIL_SMTP_PORT: "${{ secrets.EMAIL_SMTP_PORT }}" EMAIL_SMTP_PORT: ${{secrets.EMAIL_SMTP_PORT}}
EMAIL_USERNAME: "${{ secrets.EMAIL_USERNAME }}" EMAIL_USERNAME: ${{secrets.EMAIL_USERNAME}}
EMAIL_PASSWORD: "${{ secrets.EMAIL_PASSWORD }}" EMAIL_PASSWORD: ${{secrets.EMAIL_PASSWORD}}
EMAIL_FROM_ADDRESS: "${{ secrets.EMAIL_FROM_ADDRESS }}"
expose: expose:
- "8000" - "8000"
volumes: volumes:
+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']) SSL_KEY = _get(_conf, ['ssl', 'key'], DEFAULTS['ssl']['key'])
# Email settings # Email settings
def _get_email_env(name, default=''): EMAIL_ENABLED = bool(os.getenv('EMAIL_ENABLED', False))
value = os.getenv(name) EMAIL_SMTP_HOST = str(os.getenv('EMAIL_SMTP_HOST', False))
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_SMTP_PORT = int(os.getenv('EMAIL_SMTP_PORT', 587)) EMAIL_SMTP_PORT = int(os.getenv('EMAIL_SMTP_PORT', 587))
EMAIL_USE_TLS = True EMAIL_USE_TLS = True
EMAIL_USERNAME = _get_email_env('EMAIL_USERNAME') EMAIL_USERNAME = str(os.getenv('EMAIL_USERNAME', False))
EMAIL_PASSWORD = _get_email_env('EMAIL_PASSWORD') EMAIL_PASSWORD = str(os.getenv('EMAIL_PASSWORD', False))
EMAIL_FROM_ADDRESS = ( EMAIL_FROM_ADDRESS = _get(_conf, ['email', 'from_address'], EMAIL_USERNAME)
_get_email_env('EMAIL_FROM_ADDRESS')
or _get(_conf, ['email', 'from_address'], '')
or EMAIL_USERNAME
)
EMAIL_DEFAULT_SENDER_NAME = "Invario Inventarsystem Sender" EMAIL_DEFAULT_SENDER_NAME = "Invario Inventarsystem Sender"
EMAIL_TIMEOUT_SECONDS = 20 EMAIL_TIMEOUT_SECONDS = 20
+2 -10
View File
@@ -3,18 +3,11 @@ from email.mime.text import MIMEText
from email.mime.application import MIMEApplication from email.mime.application import MIMEApplication
import smtplib import smtplib
import time import time
import logging
import Web.modules.database.settings as cfg import Web.modules.database.settings as cfg
logger = logging.getLogger(__name__)
def _build_smtp_client(): def _build_smtp_client():
if not cfg.EMAIL_SMTP_HOST:
raise RuntimeError('EMAIL_SMTP_HOST ist nicht konfiguriert')
smtp = smtplib.SMTP( smtp = smtplib.SMTP(
cfg.EMAIL_SMTP_HOST, cfg.EMAIL_SMTP_HOST,
cfg.EMAIL_SMTP_PORT, 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: 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.""" """Send a plain/HTML message, optionally with one PDF attachment."""
if not cfg.MODULES.is_enabled("mail"): 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 return False
recipients = _normalize_recipients(email) recipients = _normalize_recipients(email)
if not recipients: if not recipients:
logger.warning("Email delivery skipped because no recipients were provided")
return False return False
body_message = note body_message = note
@@ -112,7 +104,7 @@ def _send_message(email: list | str, subject: str, note: str, sender: str, attac
return True return True
except Exception as e: except Exception as e:
logger.exception("Email delivery failed: %s", e) print(f"Debug: Fehler beim Senden der E-Mail: {e}")
return False return False
finally: finally:
if smtp: if smtp: