Using Mutt

Created on August 29, 2000
Development stage: pre-Alpha
Last updated on January 15, 2001

As a beginning Linux user, you may have been encouraged to use pine as your mail client. You might even be using a graphical e-mail client such as Balsa, Evolution, or KMail. While these are all pretty good, you may want to take your e-mailing to the next level. By this, I mean efficiency and flexibility. By efficiency and flexibility, some examples I can think of are customizable colors, your choice of sorting methods, and your option to choose any outside editor that you wish to use. All this makes you more efficient since mutt is mostly key-driven; you'll only be efficient once you know the keys, but once you get past that, it's a cinch.

Hopefully this document will be successful in helping you get started with using mutt. A lot of the stuff that you're about to read took me a while to figure out, so hopefully in the spirit of the rest of this guide, I will explain what I've learned in a useful manner.

Getting the Source Package

A lot of the cool/exotic features in Mutt have to be compiled in, such as SSL and IMAP support. If you're not sure, it's probably best to grab something and compile it anyway. Most distributions include mutt, and you can skip this step if you want to experiment with mutt's more common features, which are compiled in.

You can get Mutt as a tarball, or alternatively, keep up with its constant development in CVS. (If you have no idea what CVS is, just stick with the tarball.) You can find a list of download sites at http://www.mutt.org/download.html that point to tarballs and source packages. The instructions for using the CVS version of Mutt are in the README file after you extract the mutt tarball. I usually use ftp://ftp.mutt.org/pub/mutt/devel/ when I need to get a tarball. The development version has cool stuff like IMAP with SSL so that I read my mail off the server and it is encrypted.

Common configure options

So you've decided to compile a custom Mutt yourself. Below are some common options that I personally use pretty often. You can get the rest of the options by typing ./configure --help | less in the Mutt source tree.

Configuring Your Personal .muttrc

There is a file called .muttrc that lives in your home directory. The best thing for you would probably be to grab Muttrc which should have been installed as a default configuration file for Mutt. If you compiled with prefix /opt then the Muttrc sample file for you should be in /opt/etc/Muttrc. Do a cp /opt/etc/Muttrc ~/.muttrc and then edit it.

Multiple .muttrc Files

You may want to have multiple Mutt configuration files. This is the kind of setup that I have because I have an e-mail address with an IMAP mailbox on joshisanerd.com and another one with depgo.com. So, when I reply to my mail on joshisanerd.com I want it to say that it came from jtg@joshisanerd.com, while with the depgo.com account I want it to say it came from jtg@depgo.com. How do I go about doing this?

I have a Mutt configuration file for each account. The one for my joshisanerd.com account is ~/.muttrc, that is, my default. The one for my depgo.com account is ~/.muttrc.depgo. By default, mutt will look at ~/.muttrc when it loads up, but when I need to tell Mutt that I want my depgo.com setup, I run Mutt with the -F flag. So, when I check and write my jtg@depgo.com e-mail, I run mutt -F ~/.muttrc.depgo. That tells mutt to use ~/.muttrc.depgo as my configuration file.

Look at the section Shell Aliases for even more tips on how to make multiple e-mail accounts easier for you.

IMAP Mailboxes

To access your inbox not as a file but as an IMAP mailbox (a mailbox stored on a server), refer to your inbox as "{mail.server.com}inbox" so it will look for the inbox on the IMAP server. For example, my IMAP server is mail.joshisanerd.com, so in my Mutt configuration file, the line I have to specify my inbox is:

set spoolfile="{mail.joshisanerd.com}inbox"

If I already have something set in my configuration file, I can tell Mutt to look somewhere else temporarily. This can be done by running mutt -f {mail.somewhere-else.com}inbox. Also, if I want to look at a locally stored mailbox file, I can run mutt -f ~/Mail/somefile to open up Mail/somefile in my home directory instead of opening up the inbox on an IMAP mail server.

Procmail-sorted Mailboxes

If you use procmail to sort your e-mail, you can read them by typing mutt -f ~/mail/mailbox, where ~/mail is the directory in your home directory that you decided to put all your procmail-sorted e-mail, and mailbox is a particular mailbox e-mail was sorted to. Most people have more than one mailbox where procmail sorts their e-mail off to.

You can also add a shell alias so that you don't have to type out the entire commandline with the -f flag and all.

Using Your Personal Editor of Choice

Mutt allows you to use your personal editor of choice, be it pico, emacs, vim, joe, jed, and so on. It can do this because Mutt creates a temporary file whenever you compose an e-mail, and you can edit that temporary file with whichever editor you prefer. Thus, you can edit e-mail messages with whatever editor you want. It's only what you would expect from a flexible Unix e-mail client.

In your Mutt configuration file (~/.muttrc) put the following line in or change the existing setting:

set editor="emacs -nw"

You can set it to something other than "emacs -nw" to something like "vim" or "pico" or whatever else you want to choose. I just use "emacs -nw" because I prefer to use the Emacs editor in a console environment (which is what the -nw flag does).

Keybindings

The default keybindings that will probably get you around on a standard configuration are:

  1. 'm' to compose a new message
  2. [Enter] to read a message
  3. 'a' to attach a message (after composing)
  4. 'y' to send a message (after composing)

There are various keybindings that you can map yourself. Here's the section of my .muttrc file.

# Keybindings

bind pager o next-page
bind pager w previous-page
bind pager j next-line
bind pager k previous-line
bind pager n next-entry
bind pager p previous-entry

bind index n next-entry
bind index p previous-entry

bind attach n next-entry
bind attach p previous-entry

The way I have it set up, I scroll up, typing "o" while reading a message will scroll me to the next page, while typing "w" will scroll me an entire page back. Typing "j" and "k" will do the same thing for me only just a line at a time. "n" and "p" will take me to the next and previous messages, respectively. The same thing happens with "n" and "p" when I view attachments.

Shell Aliases

Once you have separate .muttrc.* files for each e-mail account that you have, it would be a cool thing if you could type a separate command to read the mail in each account. I can do this because I use bash as my shell (you probably are too). The cool thing about this is that I can have aliases and tab completion. I'll tell you how both of these make me faster in writing e-mail.

My aliases are "nerdmutt" (for my joshisanerd.com account), "depgomutt" (for my depgo.com account) and "spinmutt" (for my spinway.com account, which is for work). I added these to my .bashrc file in my home directory so that they look like this in the file:

alias depgomutt="/opt/bin/mutt -F ~/.muttrc.depgo"
alias nerdmutt="/opt/bin/mutt"
alias spinmutt="/opt/bin/mutt -F ~/.muttrc.spinway"

Tab completion is a really nifty feature in bash and other shells. I'll talk about bash in particular since that's what's included with Red Hat and mostly every distribution out there as a default. I can work faster because I can just type "dep" and hit the tab key, and it finishes to "depgomutt" since there is no other command or alias that starts with "dep". The same goes for "nerd". On Red Hat, there was actually a spin program so I simply typed "spinm" before hitting tab.

Using Emacs to Write E-mail

For the longest time, I avoided using emacs at all--for anything. I got annoyed by the little files it left around with the "~" appended to the filenames that I edited. I didn't want to use it to write e-mail especially, because I didn't know how to get it to justify all my text and word wrap my paragraphs like pico's Ctrl-J function.

I found out that I can justify my paragraphs by pressing M-q (meta-Q which is really Alt-Q) or [Esc]-q. After I found that out, I just started using emacs to write my e-mail.

Mutt puts me in emacs to write messages. As I'm writing it, I type C-x C-s (that is, Ctrl-x and then Ctrl-s) to save my mail as I'm writing it, in case something happens to my computer while I'm writing it. As always, it's a good idea to save. And then when I'm done, I type C-x C-c to exit. (You have to love the keystrokes.)

Other Resources

http://www.linuxworld.com/linuxworld/lw-1999-12/lw-12-mutt.html