Schule als Staat Projekt Web, Dokumente, etc.
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.

41 lignes
1.5KB

  1. from django.core import mail
  2. from django.conf import settings
  3. NOT_SENT, SENT, PARTLY_SENT = 0, 1, 2
  4. def send_from_arbeitsministerium(subject, content, recipients, reply_to=None):
  5. return send(subject, content, settings.EMAIL_ARBEITSMINISTERIUM, recipients,
  6. reply_to=reply_to,
  7. auth_user=settings.EMAIL_ARBEITSMINISTERIUM_USER,
  8. auth_password=settings.EMAIL_ARBEITSMINISTERIUM_PASSWORD)
  9. def send_from_info(subject, content, recipients, reply_to=None):
  10. return send(subject, content, settings.EMAIL_INFO, recipients,
  11. reply_to=reply_to,
  12. auth_user=settings.EMAIL_INFO_USER,
  13. auth_password=settings.EMAIL_INFO_PASSWORD)
  14. def send(subject, content, sender, recipients, reply_to=None,
  15. auth_user=None, auth_password=None):
  16. failed, succeeded = False, False
  17. if type(recipients) != list:
  18. recipients = [recipients]
  19. with mail.get_connection(username=auth_user, password=auth_password) as conn:
  20. for recipient in set(recipients):
  21. try:
  22. msg = mail.EmailMessage(subject, content, sender, recipients,
  23. reply_to=reply_to,
  24. connection=conn)
  25. msg.send()
  26. except Exception as e:
  27. print("Error when sending mail:", e)
  28. failed = True
  29. else:
  30. succeeded = True
  31. return NOT_SENT if failed and not succeeded else SENT if not failed\
  32. and succeeded else PARTLY_SENT