further bugfixing in parsers & clean up formatting.py
[logparse.git] / logparse / mail.py
index ecd7afcd7b49baad3632544ecf37a0c8ff30ca52..439b9c79c5a0b6f1a2121c2bc33580ca87b876e3 100644 (file)
@@ -24,13 +24,13 @@ def mailprep(htmlin, stylesheet):
     return htmlout
 
 
-def sendmail(mailbin, body, recipient, subject, *sender):
+def sendmail(mailbin, body, recipient, subject, html=True, *sender):
     logger.debug("Sending email")
-    msg = MIMEText(body, 'html')
+    msg = MIMEText(body, 'html' if html else 'plain')
     if sender:
         msg["From"] = sender
     msg["To"] = recipient
-    msg["Content-type"] = "text/html: te: text/html"
+    msg["Content-type"] = "text/html: te: text/html" if html else "text/plain: te: text/plain"
     msg["Subject"] = subject
     mailproc = subprocess.Popen([mailbin, "--debug-level=" + str(10 if logging.root.level == logging.DEBUG else 0), "-t"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
     logger.debug("Compiled message and opened process")