Reading HTML email with Mutt

Posted by Steve on Mon 10 Jan 2005 at 15:13

Tags: ,

Mutt is a console based mail client which can connect to IMAP, or POP3 mail servers. It can also read and write to local mailboxes. For a console client it's very sophisticated, allowing you to customize your setup enormously. One thing that it lacks by default is the ability to read HTML emails though.

If you wish to view HTML mails inside the mutt user interface you'll need to make two changes.

First of all you setup a mailcap file which will automatically dump the HTML text to a readable text-only display, via lynx, links, or w3m. Then you need to tell Mutt that it should do this automatically for all HTML files.

Save the following in a file called ".mailcap" in your home directory. If you already have such a file just add it to the end:

text/html;                      links %s; nametemplate=%s.html
text/html;                      links -dump %s; nametemplate=%s.html; copiousoutput

If you prefer a different program to render your HTML you can change the links command to that instead - for example w3m, or lynx.

Now we tell mutt that it should automatcally view the text/html parts of message by adding the following to the .muttrc file in our home directory:

auto_view text/html

These two changes should be enough to make sure that Mutt will dispaly HTML mails for us, and allow us to reply to them properly.

Many more things in mutt can be customized, and if you're using it for any length of time you're definately encouraged to read the mutt manual available on the Mutt homepage.

 

 


Posted by Anonymous (82.182.xx.xx) on Tue 11 Jan 2005 at 08:34
/dev/null

[ Parent | Reply to this comment ]

Posted by davee (80.68.xx.xx) on Tue 11 Jan 2005 at 10:28

/dev/null

Damn, you beat me to it ...

[ Parent | Reply to this comment ]

Posted by Anonymous (68.163.xx.xx) on Sun 16 Jan 2005 at 22:30
And I reply back with /dev/zero .... :)

[ Parent | Reply to this comment ]

Posted by Anonymous (217.230.xx.xx) on Thu 3 Feb 2005 at 16:16
http://w3m.sourceforge.net/

W3M is by far the best ncurses-browser.

Try it.

Another thing: why did you not include a tip for opening the HTML-mail in a new tab in Firefox via "firefox -remote"?

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Thu 3 Feb 2005 at 16:18
[ View Steve's Scratchpad | View Weblogs ]

Because I only read email with mutt, that's why!

I've used IMAP, POP3, and various clients over the years, but nothing has the power and customization of Mutt, except possibly emacs..

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by dannyboy (128.253.xx.xx) on Mon 14 Feb 2005 at 18:29
I use html2text, and this mailcap entry:

text/html; /usr/bin/html2text -nobs %s; copiousoutput; description=HTML Text

-nobs (no backspace) tells it to exclude special characters for bold and similar that are interpreted by less.

(I wonder if this is like slashdot, and posting to an old article is like talking out loud in an empty room.)

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Mon 14 Feb 2005 at 19:08
[ View Steve's Scratchpad | View Weblogs ]

At least I've seen the comment - as will anybody else that arrives here via google :)

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by dannyboy (128.253.xx.xx) on Wed 16 Feb 2005 at 17:05
After some experimentation, I found that links is far superior to html2text. links runs faster, and produces better formatted output. html2text will actually seem to lock up on complicated and ugly HTML mail (I suspect it's just being slow). links handles those same messages elegantly.

Thanks, Steve! My ~/.mailcap has been updated.

[ Parent | Reply to this comment ]

Posted by Anonymous (213.112.xx.xx) on Sat 24 Dec 2005 at 11:37
I'm reading your comment now, so no sir :D

[ Parent | Reply to this comment ]

Posted by Anonymous (2001:0xx:0xx:0xxx:0xxx:0xxx:xx) on Wed 7 Jan 2009 at 16:53
Definately not - three years on your echoes ring true. Thanks for the tip on html2text, makes email usable again :)

[ Parent | Reply to this comment ]

Posted by Anonymous (163.181.xx.xx) on Tue 4 Jan 2011 at 22:35
Still reading this in 2011, your comment is immortal!

[ Parent | Reply to this comment ]

Posted by Anonymous (12.192.xx.xx) on Thu 23 Feb 2012 at 17:32
... and carrying forward to 2012. Mutt (and this comment) lives on!!

[ Parent | Reply to this comment ]

Posted by Anonymous (85.230.xx.xx) on Tue 18 Dec 2012 at 13:56
Soon to be 2013, and still reading your comment.

[ Parent | Reply to this comment ]

Posted by Anonymous (213.140.xx.xx) on Thu 17 Jan 2013 at 13:39
Your comment has been read in 2013 as well :-)

[ Parent | Reply to this comment ]

Posted by Anonymous (173.252.xx.xx) on Tue 21 Jan 2014 at 21:02
2014, too!

[ Parent | Reply to this comment ]

Posted by Anonymous (94.77.xx.xx) on Sun 2 Mar 2014 at 07:19
helped me, too, thanks a lot!

[ Parent | Reply to this comment ]

Posted by Anonymous (212.110.xx.xx) on Tue 6 May 2014 at 20:43
2025 too!

[ Parent | Reply to this comment ]

Posted by Anonymous (82.38.xx.xx) on Sat 10 Dec 2005 at 11:02
Just the job! So much simpler and less convoluted that other advice Google provided. This works just fine for mutt on Ubuntu 5.10.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.163.xx.xx) on Fri 6 Apr 2007 at 01:19
Adding something to ~/.mailcap doesn't work for me.
I need to create/add it to ~/.mutt/mailcap

Also, I have ~/.mutt/muttrc instead of ~/.muttrc

Using debian 'testing', April 2007.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.5.xx.xx) on Wed 27 Feb 2008 at 10:34
I also add this so that it picks text/plain if it has a choice:

alternative_order text/plain

[ Parent | Reply to this comment ]

Posted by Anonymous (46.65.xx.xx) on Fri 11 Jan 2013 at 16:28
5 years later, I find this gem.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.110.xx.xx) on Tue 29 Jul 2014 at 12:21
You are my hero!

[ Parent | Reply to this comment ]

Posted by Anonymous (129.128.xx.xx) on Fri 16 May 2008 at 19:18
Great .. works as advertised ;)

BTW, do you know how to get links to decode characters properly? I'd like to read html email with mutt encapsulating Chinese characters. Thanks.

[ Parent | Reply to this comment ]

Posted by Anonymous (203.200.xx.xx) on Fri 26 Sep 2008 at 05:51
Works smooth!!

[ Parent | Reply to this comment ]

Posted by Anonymous (144.32.xx.xx) on Wed 22 Jul 2009 at 17:24
If you add "-html-numbered-links 1" to the links command then you also get a nice list of links at the bottom of the page.

[ Parent | Reply to this comment ]

Posted by Anonymous (72.173.xx.xx) on Mon 5 Apr 2010 at 17:29
I've been using mutt for about 15 years and complaining about html mail for the same period. I just delved into handling the problem with mutt. The suggested fix worked without a hitch. Much thanks!

[ Parent | Reply to this comment ]

Posted by Anonymous (69.124.xx.xx) on Thu 15 Jul 2010 at 01:09
Arrived here via google as you say and it just made mutt better than everything else I've used. Steve++

[ Parent | Reply to this comment ]

Posted by Anonymous (88.128.xx.xx) on Fri 17 Dec 2010 at 07:38
Thanks!

[ Parent | Reply to this comment ]

Posted by Anonymous (88.78.xx.xx) on Mon 7 Feb 2011 at 20:09
Great tip, thanks. I just came back to mutt after years of evolution, thunderbird and mail.app, and it's unbeatable.

Timo

[ Parent | Reply to this comment ]

Posted by Anonymous (192.100.xx.xx) on Tue 15 Feb 2011 at 08:49
And to get öäå working properly, use w3m and set charset in ~/.mailcap:

text/html; /usr/bin/w3m -I %{charset} -T text/html -dump; copiousoutput;

[ Parent | Reply to this comment ]

Posted by Anonymous (90.179.xx.xx) on Mon 18 Jul 2011 at 12:16
w3m works SO MUCH BETTER for non-ASCII text or mixed encodings, I consider it a far superior solution (I get here attachments with utf-8, iso-8859-2, iso-8859-1,...) and it gets it ALL right. links? forget it...

[ Parent | Reply to this comment ]

Posted by Anonymous (141.3.xx.xx) on Thu 18 Oct 2012 at 16:42
thank you, this one helped a lot!

[ Parent | Reply to this comment ]

Posted by Anonymous (192.109.xx.xx) on Thu 18 Apr 2013 at 09:50
w3m seems really slow on Debian wheezy compared to links2, so this shows umlauts correctly with it:

text/html; links -codepage %{charset} %s; nametemplate=%s.html
text/html; links -codepage %{charset} -dump %s; nametemplate=%s.html; copiousoutput

[ Parent | Reply to this comment ]

Posted by Anonymous (192.109.xx.xx) on Thu 18 Apr 2013 at 10:19
Shoot, links2 is not able to handle all combinations but for whatever reason elinks is:

text/html; elinks %s; nametemplate=%s.html
text/html; elinks -dump %s; nametemplate=%s.html; copiousoutput

[ Parent | Reply to this comment ]

Posted by Anonymous (77.2.xx.xx) on Wed 4 Jul 2012 at 21:22
Another addition to the OP's suggestions since this thread still seems to breathe (if only slightly more so than a corpse that someone frantically tries to reanimate): I have found that the text representation most MTAs/mail clients send in the form of multipart/alternative messages is usually superior to w3m/links/lynx. Therefore I like to to add the directive

alternative_order text/plain text/html

to my configuration, which will make mutt choose plaintext before html when given the choice.

[ Parent | Reply to this comment ]

Posted by Anonymous (144.212.xx.xx) on Thu 12 Jul 2012 at 18:40
That works, but sometimes the plain text just says "Use another mail reader" or words to that effect. Of course, you can also get to the HTML part. Anyway, messages like this are usually not worth reading.

[ Parent | Reply to this comment ]

Posted by Anonymous (114.79.xx.xx) on Tue 4 Dec 2012 at 02:36
Uhm... When we reply an HTML email the quoted message is one dumped from links output. It will look ugly if the message contains intricate graphical formatting (bars, block indents etc, like ones from y*hoogroups). How can we quote the plain text version instead of HTML?

[ Parent | Reply to this comment ]

Posted by Anonymous (122.182.xx.xx) on Wed 12 Mar 2014 at 13:40
Thanks a tonne.
Yogesh

[ Parent | Reply to this comment ]

Posted by Anonymous (216.212.xx.xx) on Fri 4 Apr 2014 at 19:22
thank you for this

[ Parent | Reply to this comment ]

Posted by Anonymous (212.110.xx.xx) on Tue 29 Apr 2014 at 13:31
I have done some limited testing of opening various emails with links and w3m and I have found that w3m actually works a bit better. Thanks for the help though! P.S. if you have a ~/.mutt/mailcap file, edit that file and not the ~/.mailcap file.

So what I did was

brew install w3m

and then added the following line to my ~/.mutt/mailcap file:

text/html; w3m -I %{charset} -T text/html -dump; copiousoutput;

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 833 votes ~ 10 comments )