add journald communication capability
[logparse.git] / logparse / mail.py
index ecd7afcd7b49baad3632544ecf37a0c8ff30ca52..26a402e44eacd14b5d353e34623c9808016becdf 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")