fix(messaging): test email + EmailLog show effective config, not stale env
Some checks failed
Some checks failed
Two display bugs where admin-facing email diagnostics reported the .env-level config even when database overrides were in effect — so a prod admin who switched from SendGrid (.env) to SMTP via /admin/settings would receive a test email whose body still said "Provider: sendgrid" and "From: noreply@wizard.lu", even though the actual From header used the DB-overridden address. Confusing, and erodes trust in the page that exists specifically to verify the setup. - admin_settings.send_test_email: read get_effective_email_config(db) and display its provider + from_email in the test email's body. Also use the effective provider when stamping the audit-log row. - email_service: in the "template not found" EmailLog branch, record the effective from_email / from_name / provider from self._platform_config (already populated correctly by __init__), instead of falling back to the env-only settings.email_*. Verified by importing both modules; pure plumbing fix, no schema or behavior change for callers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1317,16 +1317,18 @@ class EmailService:
|
||||
if not resolved:
|
||||
logger.error(f"Email template not found: {template_code} ({resolved_language})")
|
||||
# Create failed log entry
|
||||
# Use the *effective* config so the audit row reflects what the
|
||||
# admin actually configured (DB overrides win over .env).
|
||||
log = EmailLog(
|
||||
template_code=template_code,
|
||||
recipient_email=to_email,
|
||||
recipient_name=to_name,
|
||||
subject=f"[Template not found: {template_code}]",
|
||||
from_email=settings.email_from_address,
|
||||
from_name=settings.email_from_name,
|
||||
from_email=self._platform_config.get("from_email", settings.email_from_address),
|
||||
from_name=self._platform_config.get("from_name", settings.email_from_name),
|
||||
status=EmailStatus.FAILED.value,
|
||||
error_message=f"Template not found: {template_code} ({resolved_language})",
|
||||
provider=settings.email_provider,
|
||||
provider=self._platform_config.get("provider", settings.email_provider),
|
||||
store_id=store_id,
|
||||
user_id=user_id,
|
||||
related_type=related_type,
|
||||
|
||||
Reference in New Issue
Block a user