Team Ai
Apppublic

Underground-Digital/Workflow-Engine

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
mail_reset_password_task.py42 linesDownload Raw Back to tasks
1import logging2import time3 4import click5from celery import shared_task6from flask import render_template7 8from extensions.ext_mail import mail9 10 11@shared_task(queue="mail")12def send_reset_password_mail_task(language: str, to: str, code: str):13    """14    Async Send reset password mail15    :param language: Language in which the email should be sent (e.g., 'en', 'zh')16    :param to: Recipient email address17    :param code: Reset password code18    """19    if not mail.is_inited():20        return21 22    logging.info(click.style("Start password reset mail to {}".format(to), fg="green"))23    start_at = time.perf_counter()24 25    # send reset password mail using different languages26    try:27        if language == "zh-Hans":28            html_content = render_template("reset_password_mail_template_zh-CN.html", to=to, code=code)29            mail.send(to=to, subject="设置您的 Dify 密码", html=html_content)30        else:31            html_content = render_template("reset_password_mail_template_en-US.html", to=to, code=code)32            mail.send(to=to, subject="Set Your Dify Password", html=html_content)33 34        end_at = time.perf_counter()35        logging.info(36            click.style(37                "Send password reset mail to {} succeeded: latency: {}".format(to, end_at - start_at), fg="green"38            )39        )40    except Exception:41        logging.exception("Send password reset mail to {} failed".format(to))42