mail.py 686 B

1234567891011121314151617181920212223
  1. from mailer import Message, Mailer
  2. def mail_admins(subject, message, fail_silently=False):
  3. """Send a message to the admins in conf.ADMINS."""
  4. from celery import conf
  5. if not conf.ADMINS:
  6. return
  7. to = ", ".join(admin_email for _, admin_email in conf.ADMINS)
  8. username = conf.EMAIL_HOST_USER
  9. password = conf.EMAIL_HOST_PASSWORD
  10. message = Message(From=conf.SERVER_EMAIL, To=to,
  11. Subject=subject, Body=message)
  12. try:
  13. mailer = Mailer(conf.EMAIL_HOST, conf.EMAIL_PORT)
  14. username and mailer.login(username, password)
  15. mailer.send(message)
  16. except Exception:
  17. if not fail_silently:
  18. raise