You can do this with mutt's mime support.
In addition, you can use this with Autoview to denote two commands for viewing an attachment, one to be viewed automatically, the other to be viewed
interactively from the attachment menu.
Essentially, you include two options in your
text/html; luakit '%s' &; test=test -n "$DISPLAY"; needsterminal;
text/html; lynx -dump %s; nametemplate=%s.html; copiousoutput;
The first entry tests that
X is running, and if it is, it hands the file to luakit. The default, however, is determined by the
copiousoutput tag, so it will be rendered in Mutt by lynx.
You will need these options in your
auto_view text/html # view HTML automatically
alternative_order text/plain text/enriched text/html # save HTML for last
If you want to look at it in your browser, it is just a matter of hitting v to view the attached HTML and then m to send it to mailcap.
For convenience, I bind Enter to that function in
1. Note, I don't use lynx or luakit, so these options are indicative only.
Shamelessly reproduced from this blog post: https://jasonwryan.com/blog/2012/05/12/mutt/
bind attach <return> view-mailcap