other.py 652 B

1234567891011121314151617181920
  1. from django.conf import settings
  2. from django.template.loader import render_to_string
  3. from django.utils.html import strip_tags
  4. from django.core.mail import send_mail
  5. def send_notify_mail(subject: str, message_template: str, recipient_list: list, context: dict):
  6. try:
  7. html_message = render_to_string(message_template, context)
  8. plain_message = strip_tags(html_message)
  9. send_mail(
  10. subject,
  11. plain_message,
  12. settings.DEFAULT_FROM_EMAIL,
  13. recipient_list,
  14. html_message=html_message
  15. )
  16. except Exception as e:
  17. print(f"Error when sending an e-mail: {e}")