refactor: centralize email internationalization handling (#22752)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
-LAN-
2025-07-23 00:26:00 +08:00
committed by GitHub
parent 5c7f0a533a
commit 0f4809b9b8
11 changed files with 1200 additions and 289 deletions

View File

@@ -1,15 +1,17 @@
import logging
import time
from collections.abc import Mapping
import click
from celery import shared_task # type: ignore
from flask import render_template_string
from extensions.ext_mail import mail
from libs.email_i18n import get_email_i18n_service
@shared_task(queue="mail")
def send_enterprise_email_task(to, subject, body, substitutions):
def send_enterprise_email_task(to: list[str], subject: str, body: str, substitutions: Mapping[str, str]):
if not mail.is_inited():
return
@@ -19,11 +21,8 @@ def send_enterprise_email_task(to, subject, body, substitutions):
try:
html_content = render_template_string(body, **substitutions)
if isinstance(to, list):
for t in to:
mail.send(to=t, subject=subject, html=html_content)
else:
mail.send(to=to, subject=subject, html=html_content)
email_service = get_email_i18n_service()
email_service.send_raw_email(to=to, subject=subject, html_content=html_content)
end_at = time.perf_counter()
logging.info(