Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

mail_invite_member_task.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 configs import dify_config
  7. from extensions.ext_mail import mail
  8. from services.feature_service import FeatureService
  9. @shared_task(queue="mail")
  10. def send_invite_member_mail_task(language: str, to: str, token: str, inviter_name: str, workspace_name: str):
  11. """
  12. Async Send invite member mail
  13. :param language
  14. :param to
  15. :param token
  16. :param inviter_name
  17. :param workspace_name
  18. Usage: send_invite_member_mail_task.delay(language, to, token, inviter_name, workspace_name)
  19. """
  20. if not mail.is_inited():
  21. return
  22. logging.info(
  23. click.style("Start send invite member mail to {} in workspace {}".format(to, workspace_name), fg="green")
  24. )
  25. start_at = time.perf_counter()
  26. # send invite member mail using different languages
  27. try:
  28. url = f"{dify_config.CONSOLE_WEB_URL}/activate?token={token}"
  29. if language == "zh-Hans":
  30. template = "invite_member_mail_template_zh-CN.html"
  31. system_features = FeatureService.get_system_features()
  32. if system_features.branding.enabled:
  33. application_title = system_features.branding.application_title
  34. template = "without-brand/invite_member_mail_template_zh-CN.html"
  35. html_content = render_template(
  36. template,
  37. to=to,
  38. inviter_name=inviter_name,
  39. workspace_name=workspace_name,
  40. url=url,
  41. application_title=application_title,
  42. )
  43. mail.send(to=to, subject=f"立即加入 {application_title} 工作空间", html=html_content)
  44. else:
  45. html_content = render_template(
  46. template, to=to, inviter_name=inviter_name, workspace_name=workspace_name, url=url
  47. )
  48. mail.send(to=to, subject="立即加入 Dify 工作空间", html=html_content)
  49. else:
  50. template = "invite_member_mail_template_en-US.html"
  51. system_features = FeatureService.get_system_features()
  52. if system_features.branding.enabled:
  53. application_title = system_features.branding.application_title
  54. template = "without-brand/invite_member_mail_template_en-US.html"
  55. html_content = render_template(
  56. template,
  57. to=to,
  58. inviter_name=inviter_name,
  59. workspace_name=workspace_name,
  60. url=url,
  61. application_title=application_title,
  62. )
  63. mail.send(to=to, subject=f"Join {application_title} Workspace Now", html=html_content)
  64. else:
  65. html_content = render_template(
  66. template, to=to, inviter_name=inviter_name, workspace_name=workspace_name, url=url
  67. )
  68. mail.send(to=to, subject="Join Dify Workspace Now", html=html_content)
  69. end_at = time.perf_counter()
  70. logging.info(
  71. click.style(
  72. "Send invite member mail to {} succeeded: latency: {}".format(to, end_at - start_at), fg="green"
  73. )
  74. )
  75. except Exception:
  76. logging.exception("Send invite member mail to {} failed".format(to))