Selaa lähdekoodia

Sending of e-mails did not work, masked by fail_silently. Now warns on error if enabled.

Ask Solem 14 vuotta sitten
vanhempi
commit
c10da74a3d
1 muutettua tiedostoa jossa 10 lisäystä ja 1 poistoa
  1. 10 1
      celery/utils/mail.py

+ 10 - 1
celery/utils/mail.py

@@ -1,4 +1,5 @@
 import smtplib
+import warnings
 
 try:
     from email.mime.text import MIMEText
@@ -6,6 +7,10 @@ except ImportError:
     from email.MIMEText import MIMEText
 
 
+class SendmailWarning(UserWarning):
+    """Problem happened while sending the e-mail message."""
+
+
 class Message(object):
 
     def __init__(self, to=None, sender=None, subject=None, body=None,
@@ -14,6 +19,7 @@ class Message(object):
         self.sender = sender
         self.subject = subject
         self.body = body
+        self.charset = charset
 
         if not isinstance(self.to, (list, tuple)):
             self.to = [self.to]
@@ -60,6 +66,9 @@ def mail_admins(subject, message, fail_silently=False):
                         conf.EMAIL_HOST_USER,
                         conf.EMAIL_HOST_PASSWORD)
         mailer.send(message)
-    except Exception:
+    except Exception, exc:
         if not fail_silently:
             raise
+        warnings.warn(SendmailWarning(
+            "Mail could not be sent: %r %r" % (
+                exc, {"To": to, "Subject": subject})))