Mutt is a text-based e-mail client for UN*X systems. It doesn't do nicely formatted HTML e-mails or images, but it's extremely customizable and completely keyboard-driven.
I have been using Mozilla's Thunderbird for a while now and I'm not completely satisfied with the way it handles mailboxes. It's time to try something 'new': Mutt. The plan is to use Mutt for all things e-mail for a full month.
A word of warning: Mutt is known for its complicated setup (there are literally hundreds of configuration commands), and I had to stitch together quite a few blog posts before I got a working setup. If you don't like braking and rebuilding stuff or hunting down a missing comma for half an hour, Mutt is probably not for you.
Fetching mails with isync
I use isync to synchronize my e-mail locally and Mutt to read and send e-mails. IMAP only. Mutt can do more, much more, but you will have to look elsewhere for that.
Mutt comes with IMAP support built-in. This works superbly, but is a bit slower when dealing with larger mailboxes. Mutt's built-in IMAP support fetches your e-mail as soon as you start the program. There is a cache that is quite fast but requires a bit of patience every time you open the program. It also means you can't read your e-mail offline. I want a little more and use isync to download or better, synchronise, my e-mail locally via a crontab.
isync syncs your different e-mail accounts to a local folder structure. As much as it can be used outside of Mutt, they work together nicely and it makes Mutt faster and available on the go.
Be careful because isync doesn't download but synchronizes your mailbox! If you mess up the configuration, you could easily delete all your mail from the mailserver. Play with a test account first and/or make sure you have a backup before you try this. You do have a backup, right?
The executable isync is called 'mbsync' and can be configured with a '.mbsyncrc' configuration file in your homedir. Let's configure our different IMAP accounts and add a crontab to fetch our new e-mail.
Create a '~/.mbsyncrc' file with the following:
Repeat this for every account you wish to synchronize. The example will only synchronize your inbox and sent mailbox, add other folders you might need, like a trash or spam folder. I had to create each of the account directories in '~/.mail' manually as well.Now add a crontab command to fetch all e-mail every 5 minutes:
The 'mbsync -a' command fetches all configured e-mail accounts. You can define different schedules with 'mbsync john', for example, which only synchronizes the firstname.lastname@example.org account in our configuration example.
Once done, you will see a folder for each channel in the ~/.mail/john directory with all your e-mails. You now have have an offline copy, which is great.
Mutt time! Mutt doesn't come with a sidebar folder view out-of-the-box, but you probably want one. There is a patch, but you need to instruct Homebrew to include it when installing Mutt.
to modify the Homebrew formula and add
at the bottom of the block with all the options and add
at the end of the section with all the patches.
And, finally, install Mutt:
Muttt's config lives in the '.muttrc' file in your homedir, right next to the isync config file. However, I prefer a '.mutt' folder with a 'muttrc' (no dot here) file to have all the Mutt dependencies in a single place.
Let's start by telling Mutt where to look. Add the following to the '~/.mutt/muttrc' file:
and set some nicer defaults:
Moving on to the sidebar. The following configures the up and down arrows to select a mailbox in the sidebar and the right arrow to open the selected mailbox. It also highlights the mailboxes with new mails.
Let's configure an account. I created a file for each account and used the folder hooks to trigger the right config for the selected mailbox:
And the 'example' file in the accounts folder:
Note that the password is not encrypted here. Therefore, only use this if you know what you are doing and make sure the file is only readable for your user. There are some ways around this if this scares you, but that's beyond the scope of this post.
If your password contains special characters ($, &, %, #, * and the like), you'll need to URL encode them. This took me a while to figure out. The password will be used in the 'smtp_url' setting so it makes sense you URL encode the special characters like you would in any URL. I used irb to quickly encode my password:
The mailboxes section at the end of the file sets the mailboxes you will see in the sidebar. These have to match the mailboxes you defined earlier in the 'mbsync' configuration file. The first "Example" line is not a real mailbox, but a little hack to have a visual separation between the accounts.
You'll find plenty of Gmail example files if you want to add one of those. They are basically the same as the example above, but with Google's SMTP server and your Gmail address.
By default, Mutt saves attachments you open within Mutt to disk. This works, but is cumbersome if you simply want to look at a photo someone sent you or quickly scan an attached MS Word document. OS X has this awesome Quick Look feature that quickly opens most files without having to install separate applications. Why not use Quick Look for e-mail attachments in Mutt?
Did you know you can run Quick Look from the command line with 'qlmanage -p file'? We''ll use this trick to tell Mutt to run Quick Look when opening attachments. Add a 'mailcap' file in the '~/.mutt' folder you created earlier with the following:
Run Mutt; search for an e-mail with an attachment; press enter with the attachment selected and voila, quick previews without saving.
I obviously didn't find this all by myself so here are some of the most useful snippets I stole: