Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to create a text/plain message using Markdown formatting and transform that into a multipart/alternative message where the text/html part has been generated from the Markdown. I've tried using the filter command to filter this through a python program that creates the message, but it seems that the message doesn't get sent through properly. The code is below (this is just test code to see if I can make multipart/alternative messages at all.

import sys
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

html = """<html>
          This is <i>HTML</i>

msgbody =

newmsg = MIMEMultipart("alternative")

plain = MIMEText(msgbody, "plain")
plain["Content-Disposition"] = "inline"

html = MIMEText(html, "html")
html["Content-Disposition"] = "inline"


print newmsg.as_string()

Unfortunately, in mutt, you only get the message body sent to the filter command when you compose (the headers are not included). Once I get this working, I think the markdown part won't be too hard.

share|improve this question
I don't know if it's appropriate here: have you tried to 'set edit_headers' in muttrc? This lets you edit the whole message with your favorite editor including the headers. From that point on it only depends on the capabilities of your editor what you can do with the message. – sparkie Feb 7 '13 at 16:58
@sparkie I was hoping to automate where I could, but I think you're certainly right that I could make multipart/alternative messages this way. – Chris W. Feb 7 '13 at 20:43
just a remote idea, but I think mutt can't prevent you from temporarily setting up your "external editor" as a python script – n611x007 Jan 16 '14 at 4:00

I would comment further on the question, but am blocked due to reputation.

I attempted to create multipart alteratives in mutt in a wrapper-script to my editor as suggested by @n611x007. I successfully created a python script which accepted a editor-crafted mail, and then created a new message that was a multipart alternative of the same message.

However, mutt interpreted the resulting crafted valid multipart alternative rfc2822 mail as something that could only be a plain body, and reformulated the mutltipart as a very difficult-to-read text/plain mime component.

Therefore it's my suspicion that generating a multipart mime message via scripting isn't really possible via an interactive approach, though it certainly is possible to do so by explicitly manipulating the mime payload in the post-creation screen where one normally might create attachments etc. However, the workflow isn't good enough for something one might do regularly.

The alternate approach would be to generate the multipart alternative as part of the transmission, as a wrapper to the local sendmail command, or as a script which wraps talking to smtp/s directly. Some examples of this approach are and

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .