Reading html email with mutt

Posted on 2015-10-06 in Projects • 2 min read

Reading html emails with mutt using w3m or lynx is a pain. If mutt is running in a X11 session you might prefer to use a graphical html email renderer to read full blown html emails. Html emails are MIME multipart messages containing text/html content with an optional text/plain version (multipart/alternative). The following configuration uses htmail-view to render html mails using WebKit.

Prefer text/plain

To prefer the text/plain content in mutt you could use the following options in your muttrc:

# prefer plain text
alternative_order text/plain text/enriched text/html

Auto convertion using w3m

If an email contains no text/plain but a text/html content mutt can be configured to automaticly convert it to plain text:

# auto convert text/html MIME type to text/plain
auto_view text/html

This requires a suitable entry in your mailcap file:

# auto view using w3m
text/html; w3m -I %{charset} -T text/html; copiousoutput;

Render html attachments

You could use the following statement to configure a key binding for rendering html attachments with htmail-view:

# run viewer defined in mailcap by <return> in attach view
bind attach <return> view-mailcap

mutt uses a viewer for the MIME type defined in your mailcap file:

# htmail-view w/o focus handling
#text/html; htmail-view file://%s; test=test -n "$DISPLAY"; nametemplate=%s.html; needsterminal;

# htmail-view w/ focus handling using wmctrl
text/html; /usr/lib/htmail-view/wmctrl-wrapper file://%s; test=test -n "$DISPLAY"; nametemplate=%s.html; needsterminal;

Render html using htmail-view

Rendering single html attachments won’t show any resources (i.e. images) attached to the mail. The htmail-decode command extracts the mime parts of a mail before calling htmail-view to render the text/html part. This example binds the command as a key binding:

# handover mail to htmail-view (works only for multipart mails containing text/html payload)
macro index,pager H "<pipe-message>htmail-decode<return>" "render html mail using htmail-view"