Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mail_account_deletion_task.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. @shared_task(queue="mail")
  8. def send_deletion_success_task(to):
  9. """Send email to user regarding account deletion."""
  10. if not mail.is_inited():
  11. return
  12. logging.info(click.style(f"Start send account deletion success email to {to}", fg="green"))
  13. start_at = time.perf_counter()
  14. try:
  15. html_content = render_template(
  16. "delete_account_success_template_en-US.html",
  17. to=to,
  18. email=to,
  19. )
  20. mail.send(to=to, subject="Your Dify.AI Account Has Been Successfully Deleted", html=html_content)
  21. end_at = time.perf_counter()
  22. logging.info(
  23. click.style(
  24. "Send account deletion success email to {}: latency: {}".format(to, end_at - start_at), fg="green"
  25. )
  26. )
  27. except Exception:
  28. logging.exception("Send account deletion success email to {} failed".format(to))
  29. @shared_task(queue="mail")
  30. def send_account_deletion_verification_code(to, code):
  31. """Send email to user regarding account deletion verification code.
  32. Args:
  33. to (str): Recipient email address
  34. code (str): Verification code
  35. """
  36. if not mail.is_inited():
  37. return
  38. logging.info(click.style(f"Start send account deletion verification code email to {to}", fg="green"))
  39. start_at = time.perf_counter()
  40. try:
  41. html_content = render_template("delete_account_code_email_template_en-US.html", to=to, code=code)
  42. mail.send(to=to, subject="Dify.AI Account Deletion and Verification", html=html_content)
  43. end_at = time.perf_counter()
  44. logging.info(
  45. click.style(
  46. "Send account deletion verification code email to {} succeeded: latency: {}".format(
  47. to, end_at - start_at
  48. ),
  49. fg="green",
  50. )
  51. )
  52. except Exception:
  53. logging.exception("Send account deletion verification code email to {} failed".format(to))