Jul 17 - Fill the gaps between Single-tenant mode and Multi-tenant mode - MT7

This commit is contained in:
2026-07-17 12:54:07 -04:00
parent 8d9730e3df
commit c706489480
8 changed files with 178 additions and 16 deletions
+7 -4
View File
@@ -8,7 +8,6 @@ app/templates/billing/email/.
import logging
import threading
from urllib.parse import urlparse
from flask import current_app, render_template
from flask_mail import Message
from app import mail
@@ -92,10 +91,14 @@ def send_billing_email(to_addr: str, event_type: str, context_dict: dict):
app = current_app._get_current_object()
# Derive noreply sender from APP_BASE_URL so billing emails match the tenant domain.
# Branded From: the display NAME tracks the tenant, the ADDRESS stays the
# authenticated identity unless the domain is DNS-authorized. Resolved HERE,
# in the request context, because _send() runs on a background thread where
# g.tenant no longer exists. The previous `noreply@{netloc}` sent from the
# tenant's host regardless of SPF authorization. See app/utils/mail_utils.py.
try:
_netloc = urlparse(app.config.get('APP_BASE_URL', '')).netloc
_sender = f'noreply@{_netloc}' if _netloc else app.config.get('MAIL_DEFAULT_SENDER', '')
from app.utils.mail_utils import branded_sender
_sender = branded_sender(app.config.get('APP_BASE_URL', ''))
except Exception:
_sender = app.config.get('MAIL_DEFAULT_SENDER', '')