您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mail_reset_password_task.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import logging
  2. import time
  3. import click
  4. from celery import shared_task # type: ignore
  5. from flask import render_template
  6. from extensions.ext_mail import mail
  7. from services.feature_service import FeatureService
  8. @shared_task(queue="mail")
  9. def send_reset_password_mail_task(language: str, to: str, code: str):
  10. """
  11. Async Send reset password mail
  12. :param language: Language in which the email should be sent (e.g., 'en', 'zh')
  13. :param to: Recipient email address
  14. :param code: Reset password code
  15. """
  16. if not mail.is_inited():
  17. return
  18. logging.info(click.style("Start password reset mail to {}".format(to), fg="green"))
  19. start_at = time.perf_counter()
  20. # send reset password mail using different languages
  21. try:
  22. if language == "zh-Hans":
  23. template = "reset_password_mail_template_zh-CN.html"
  24. system_features = FeatureService.get_system_features()
  25. if system_features.branding.enabled:
  26. application_title = system_features.branding.application_title
  27. template = "without-brand/reset_password_mail_template_zh-CN.html"
  28. html_content = render_template(template, to=to, code=code, application_title=application_title)
  29. mail.send(to=to, subject=f"设置您的 {application_title} 密码", html=html_content)
  30. else:
  31. html_content = render_template(template, to=to, code=code)
  32. mail.send(to=to, subject="设置您的 Dify 密码", html=html_content)
  33. else:
  34. template = "reset_password_mail_template_en-US.html"
  35. system_features = FeatureService.get_system_features()
  36. if system_features.branding.enabled:
  37. application_title = system_features.branding.application_title
  38. template = "without-brand/reset_password_mail_template_en-US.html"
  39. html_content = render_template(template, to=to, code=code, application_title=application_title)
  40. mail.send(to=to, subject=f"Set Your {application_title} Password", html=html_content)
  41. else:
  42. html_content = render_template(template, to=to, code=code)
  43. mail.send(to=to, subject="Set Your Dify Password", html=html_content)
  44. end_at = time.perf_counter()
  45. logging.info(
  46. click.style(
  47. "Send password reset mail to {} succeeded: latency: {}".format(to, end_at - start_at), fg="green"
  48. )
  49. )
  50. except Exception:
  51. logging.exception("Send password reset mail to {} failed".format(to))