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 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import logging
  2. import time
  3. import click
  4. from celery import shared_task
  5. from configs import dify_config
  6. from extensions.ext_mail import mail
  7. from libs.email_i18n import EmailType, get_email_i18n_service
  8. logger = logging.getLogger(__name__)
  9. @shared_task(queue="mail")
  10. def send_invite_member_mail_task(language: str, to: str, token: str, inviter_name: str, workspace_name: str) -> None:
  11. """
  12. Send invite member email with internationalization support.
  13. Args:
  14. language: Language code for email localization
  15. to: Recipient email address
  16. token: Invitation token
  17. inviter_name: Name of the person sending the invitation
  18. workspace_name: Name of the workspace
  19. """
  20. if not mail.is_inited():
  21. return
  22. logger.info(click.style(f"Start send invite member mail to {to} in workspace {workspace_name}", fg="green"))
  23. start_at = time.perf_counter()
  24. try:
  25. url = f"{dify_config.CONSOLE_WEB_URL}/activate?token={token}"
  26. email_service = get_email_i18n_service()
  27. email_service.send_email(
  28. email_type=EmailType.INVITE_MEMBER,
  29. language_code=language,
  30. to=to,
  31. template_context={
  32. "to": to,
  33. "inviter_name": inviter_name,
  34. "workspace_name": workspace_name,
  35. "url": url,
  36. },
  37. )
  38. end_at = time.perf_counter()
  39. logger.info(click.style(f"Send invite member mail to {to} succeeded: latency: {end_at - start_at}", fg="green"))
  40. except Exception:
  41. logger.exception("Send invite member mail to %s failed", to)