changeset 5453:ebfab577da16

email: better logging of misconfiguration and better debug logging Always add details about emails being sent (or attempted to be sent). When a mail server is configured, log as debug, otherwise as warning. This also adds logging of recipients and headers.
author Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
date Sat, 15 Aug 2015 21:37:13 +0200
parents c3d83238afa1
children 4f364ef689ab
files kallithea/lib/celerylib/tasks.py
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/celerylib/tasks.py	Tue Sep 01 21:46:03 2015 +0200
+++ b/kallithea/lib/celerylib/tasks.py	Sat Aug 15 21:37:13 2015 +0200
@@ -290,10 +290,19 @@
     debug = str2bool(email_config.get('debug'))
     smtp_auth = email_config.get('smtp_auth')
 
-    if not mail_server:
-        log.error("SMTP mail server not configured - cannot send mail '%s' to %s", subject, ' '.join(recipients))
-        log.warning("body:\n%s", body)
-        log.warning("html:\n%s", html_body)
+    logmsg = ("Mail details:\n"
+              "recipients: %s\n"
+              "headers: %s\n"
+              "subject: %s\n"
+              "body:\n%s\n"
+              "html:\n%s\n"
+              % (' '.join(recipients), headers, subject, body, html_body))
+
+    if mail_server:
+        log.debug("Sending e-mail. " + logmsg)
+    else:
+        log.error("SMTP mail server not configured - cannot send e-mail.")
+        log.warning(logmsg)
         return False
 
     try: