Sometimes I need to send a fragment of code on google-group inline. Text does not help here; I can type it in markdown, convert it to html (using pandoc etc.), attach to mutt as text/html and send it.

There is one good solution available here but it uses external sendmail program to send email. I am using mutt which has capabilities to send emails over IMAP by itself.

  • 1
    Why not just pipe output from a command-line Markdown formatter to sendmail? Jan 9, 2014 at 2:26
  • Hmm.. shared computer! Don't want to store password for external sendmail.
    – Dilawar
    Jan 9, 2014 at 2:35
  • Is there any examples we can see of what your current results look like on google-groups?
    – slm
    Jan 9, 2014 at 3:44
  • Also you want to type things up in markdown, but have them rendered prior to attaching them to your emails, right?
    – slm
    Jan 9, 2014 at 3:53
  • This sounds like what you're asking for, but might need to be modified: dgl.cx/2009/03/html-mail-with-mutt-using-markdown. Also markdownmail.py sounded like something you could use.
    – slm
    Jan 9, 2014 at 3:55

4 Answers 4


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.

  • 1
    This is a really elegant solution! +1 Sep 23, 2015 at 9:51
  • 7
    this is nice, but it's got core flaw. it eliminates the plaintext part of the email which makes it suck to read in clients like ... mutt ;) HTML emails should have a plaintext and html component. the raw markdown should be the plaintext, the converted should be the HTML.
    – masukomi
    Jun 17, 2016 at 15:27
  • 1
    Agree with @masukomi, email clients in general send both html and text versions of the email. It would be nice to have a macro that adds the html version and leaves the original as text/plain.
    – oblitum
    Aug 25, 2017 at 17:30
  • 2
    In the end I've build my own setup for this nosubstance.me/post/mutt-secret-sauce
    – oblitum
    Sep 20, 2017 at 17:37
  • 1
    @Rastapopoulos yes: github.com/oblitum/dotfiles/issues/3#issuecomment-437954693
    – oblitum
    Nov 16, 2018 at 12:21

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" 

Sendmail is often not flexible enogh for sending mails.

I use msmtp together with mutt on particular accounts for flexible SMTP.

To use it with mutt change:

# ~/.muttrc  
set sendmail="/usr/bin/msmtp -a default"   


# ~/.msmtprc  
tls off
logfile ~/.msmtp.log  
account default   
host your.smtp.host  
port 25  
from [email protected]  
auth off  
user username  
password password  

I can send email in any format using neomutt. I just use Emacs (org-mode), instead of vim. Although, I am a vim user as well. But, I mostly use Emacs with evil-mode.

In my .muttrc I have set up the editor to be emacs instead of vim. When writing a new email, neomutt fires emacs up. Then I call "org-mode", write the message, and export to whatever format I want.

I can export to PDF format. Then I save it and attach the PDF file in my /tmp. After that I can send to whomever.

If I want the html format, I export that in the same way and I automatically can see the output, before sending the email.

Apart from that, there are many other export formats in org-mode. Just, choose what you want. For sending code to other people, just add the source code to whatever language you want. Everything is explained in the org-wiki.

You must log in to answer this question.

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