From 0decc735d69727dbe3fc956ffb0744f300cd476d Mon Sep 17 00:00:00 2001 From: Yansong Zhang <916125788@qq.com> Date: Fri, 11 Jul 2025 13:47:49 +0800 Subject: [PATCH] add zh-CN and without-brand email template for change email --- api/tasks/mail_change_mail_task.py | 72 ++++++++++++--- ...hange_mail_confirm_new_template_zh-CN.html | 88 +++++++++++++++++++ ...hange_mail_confirm_old_template_zh-CN.html | 88 +++++++++++++++++++ ...hange_mail_confirm_new_template_en-US.html | 84 ++++++++++++++++++ ...hange_mail_confirm_new_template_zh-CN.html | 84 ++++++++++++++++++ ...hange_mail_confirm_old_template_en-US.html | 84 ++++++++++++++++++ ...hange_mail_confirm_old_template_zh-CN.html | 84 ++++++++++++++++++ 7 files changed, 573 insertions(+), 11 deletions(-) create mode 100644 api/templates/change_mail_confirm_new_template_zh-CN.html create mode 100644 api/templates/change_mail_confirm_old_template_zh-CN.html create mode 100644 api/templates/without-brand/change_mail_confirm_new_template_en-US.html create mode 100644 api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html create mode 100644 api/templates/without-brand/change_mail_confirm_old_template_en-US.html create mode 100644 api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html diff --git a/api/tasks/mail_change_mail_task.py b/api/tasks/mail_change_mail_task.py index 08e55ecef3..17b534e246 100644 --- a/api/tasks/mail_change_mail_task.py +++ b/api/tasks/mail_change_mail_task.py @@ -6,6 +6,7 @@ from celery import shared_task # type: ignore from flask import render_template from extensions.ext_mail import mail +from services.feature_service import FeatureService @shared_task(queue="mail") @@ -23,21 +24,70 @@ def send_change_mail_task(language: str, to: str, code: str, phase: str): logging.info(click.style("Start change email mail to {}".format(to), fg="green")) start_at = time.perf_counter() + email_config = { + "zh-Hans": { + "old_email": { + "subject": "检测您现在的邮箱", + "template_with_brand": "change_mail_confirm_old_template_zh-CN.html", + "template_without_brand": "without-brand/change_mail_confirm_old_template_zh-CN.html" + }, + "new_email": { + "subject": "确认您的邮箱地址变更", + "template_with_brand": "change_mail_confirm_new_template_zh-CN.html", + "template_without_brand": "without-brand/change_mail_confirm_new_template_zh-CN.html" + } + }, + "en": { + "old_email": { + "subject": "Check your current email", + "template_with_brand": "change_mail_confirm_old_template_en-US.html", + "template_without_brand": "without-brand/change_mail_confirm_old_template_en-US.html" + }, + "new_email": { + "subject": "Confirm your new email address", + "template_with_brand": "change_mail_confirm_new_template_en-US.html", + "template_without_brand": "without-brand/change_mail_confirm_new_template_en-US.html" + } + } + } + # send change email mail using different languages try: - if phase == "old_email": - template = "change_mail_confirm_old_template_en-US.html" - elif phase == "new_email": - template = "change_mail_confirm_new_template_en-US.html" - else: - raise ValueError("Invalid phase") - + system_features = FeatureService.get_system_features() if language == "zh-Hans": - html_content = render_template(template, to=to, code=code) - mail.send(to=to, subject="检测您现在的邮箱", html=html_content) + if phase == "old_email": + subject = "检测您现在的邮箱" + if system_features.branding.enabled: + template = "without-brand/change_mail_confirm_old_template_zh-CN.html" + else: + template = "change_mail_confirm_old_template_zh-CN.html" + elif phase == "new_email": + subject = "确认您的邮箱地址变更" + if system_features.branding.enabled: + template = "without-brand/change_mail_confirm_new_template_zh-CN.html" + else: + template = "change_mail_confirm_new_template_zh-CN.html" + else: + raise ValueError("Invalid phase") else: - html_content = render_template(template, to=to, code=code) - mail.send(to=to, subject="Check your current email", html=html_content) + if phase == "old_email": + subject = "Check your current email" + if system_features.branding.enabled: + template = "without-brand/change_mail_confirm_old_template_en-US.html" + else: + template = "change_mail_confirm_old_template_en-US.html" + elif phase == "new_email": + subject = "Confirm your new email address" + if system_features.branding.enabled: + template = "without-brand/change_mail_confirm_new_template_en-US.html" + else: + template = "change_mail_confirm_new_template_en-US.html" + else: + raise ValueError("Invalid phase") + + + html_content = render_template(template, to=to, code=code) + mail.send(to=to, subject=subject, html=html_content) end_at = time.perf_counter() logging.info( diff --git a/api/templates/change_mail_confirm_new_template_zh-CN.html b/api/templates/change_mail_confirm_new_template_zh-CN.html new file mode 100644 index 0000000000..0139c645cc --- /dev/null +++ b/api/templates/change_mail_confirm_new_template_zh-CN.html @@ -0,0 +1,88 @@ + + + + + + + + +
+
+ + Dify Logo +
+

确认您的邮箱地址变更

+

您正在更新与您的 Dify 账户关联的邮箱地址。 + + 为了确认此操作,请使用以下验证码。 + 此验证码仅在接下来的5分钟内有效:

+
+ {{code}} +
+

如果您没有请求变更邮箱地址,请忽略此邮件或立即联系支持。

+
+ + + \ No newline at end of file diff --git a/api/templates/change_mail_confirm_old_template_zh-CN.html b/api/templates/change_mail_confirm_old_template_zh-CN.html new file mode 100644 index 0000000000..901ae55ddc --- /dev/null +++ b/api/templates/change_mail_confirm_old_template_zh-CN.html @@ -0,0 +1,88 @@ + + + + + + + + +
+
+ + Dify Logo +
+

验证您的邮箱变更请求

+

我们收到了一个变更您 Dify 账户关联邮箱地址的请求。 + + 我们收到了一个变更您 Dify 账户关联邮箱地址的请求。 + 此验证码仅在接下来的5分钟内有效:

+
+ {{code}} +
+

如果您没有请求变更邮箱地址,请忽略此邮件或立即联系支持。

+
+ + + \ No newline at end of file diff --git a/api/templates/without-brand/change_mail_confirm_new_template_en-US.html b/api/templates/without-brand/change_mail_confirm_new_template_en-US.html new file mode 100644 index 0000000000..60c12246a0 --- /dev/null +++ b/api/templates/without-brand/change_mail_confirm_new_template_en-US.html @@ -0,0 +1,84 @@ + + + + + + + + +
+

Confirm Your New Email Address

+

You’re updating the email address linked to your Dify account. + + To confirm this action, please use the verification code below. + This code will only be valid for the next 5 minutes:

+
+ {{code}} +
+

If you didn’t make this request, please ignore this email or contact support immediately.

+
+ + + \ No newline at end of file diff --git a/api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html b/api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html new file mode 100644 index 0000000000..4a8de1e0e7 --- /dev/null +++ b/api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html @@ -0,0 +1,84 @@ + + + + + + + + +
+

确认您的邮箱地址变更

+

您正在更新与您的 Dify 账户关联的邮箱地址。 + + 为了确认此操作,请使用以下验证码。 + 此验证码仅在接下来的5分钟内有效:

+
+ {{code}} +
+

如果您没有请求变更邮箱地址,请忽略此邮件或立即联系支持。

+
+ + + \ No newline at end of file diff --git a/api/templates/without-brand/change_mail_confirm_old_template_en-US.html b/api/templates/without-brand/change_mail_confirm_old_template_en-US.html new file mode 100644 index 0000000000..7f45d61427 --- /dev/null +++ b/api/templates/without-brand/change_mail_confirm_old_template_en-US.html @@ -0,0 +1,84 @@ + + + + + + + + +
+

Verify Your Request to Change Email

+

We received a request to change the email address associated with your Dify account. + + To confirm this action, please use the verification code below. + This code will only be valid for the next 5 minutes:

+
+ {{code}} +
+

If you didn’t make this request, please ignore this email or contact support immediately.

+
+ + + \ No newline at end of file diff --git a/api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html b/api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html new file mode 100644 index 0000000000..9f8bc5d1bf --- /dev/null +++ b/api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html @@ -0,0 +1,84 @@ + + + + + + + + +
+

验证您的邮箱变更请求

+

我们收到了一个变更您 Dify 账户关联邮箱地址的请求。 + + 为了确认此操作,请使用以下验证码。 + 此验证码仅在接下来的5分钟内有效:

+
+ {{code}} +
+

如果您没有请求变更邮箱地址,请忽略此邮件或立即联系支持。

+
+ + + \ No newline at end of file