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

34 line
1.2KB

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