Send email written in markdown using mutt

After you compose a message, but before sending you have lots of options available to you. Press ? to view them.

Some that may help here:

  • F to filter the attachment through an external processor
    • Use pandoc -s -f markdown -t html to convert to HTML
  • ^T to edit the attachment MIME type
    • Change from text/plain to text/html.

Now a macro that will do everything in one step. Add this to your .muttrc:

macro compose \e5 "F pandoc -s -f markdown -t html \ny^T^Utext/html; charset=utf-8\n"
set wait_key=no

To use this macro, after you have finished composing your message but before you send, press Esc then 5 to convert your markdown formatted message into HTML.

You can naturally customize this macro as you see fit. Mutt has lots of key bindings already built in, so whatever key sequence you choose to bind to, make sure it doesn't overwrite something else (or it's something you can live without).


The option set wait_key=no suppresses Mutt's Press any key to continue... prompt when external commands are run. If wait_key is yes (which is the default) you'll have to press Esc, then 5, then any other key to continue.


You can send e-mails also as a multipart/alternative containing both text/plain and text/html.

Requirements: pandoc

Basically it creates from markdown message plaintext and html5. Creates attachments from those parts, marks them as inline attachments, set correct mime type and combine them into mutlipart message.

Any other attachments are supposed to be added after running this macro in compose menu. Optionally signing/encrypting message should be done as the final step

macro compose ,m \
"<enter-command>set pipe_decode<enter>\
<pipe-message>pandoc -f gfm -t plain -o /tmp/msg.txt<enter>\
<pipe-message>pandoc -s -f gfm -t html5 -o /tmp/msg.html<enter>\
<enter-command>unset pipe_decode<enter>a^U/tmp/msg.txt\n^Da^U/tmp/msg.html\n^D^T^Utext/html; charset=utf-8\n=DTT&d^U\n" \
"Convert markdown gfm to HTML and plain" 

Tags:

Scripting

Mutt