You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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