mugshot, larkspur

g13n


Gopal Venkatesan's Former Journal

My writings on free/open source software and other technologies


Previous Entry Share Next Entry
Getting started with Mutt and IMAP
mugshot, larkspur
g13n

This content has been updated and moved to a new place.

All mail clients suck. This one just sucks less.

That is what the mail client Mutt claims, and yes it is very true. Even though at work I use Thunderbird, I enjoy using Mutt at home. It gives me complete control using just the keyboard, much like my text editor.

Installing Mutt

Though almost all Unices and Unix-like operating systems bundle Mutt with them, I recommended that you download the source and build it. This is because the bundled version is most likely an older version, or the stable version (1.4.x). The development version (1.5.x) has loads of good features including built-in SMTP support. Now if you are a true Unix geek you would argue that one program should do only one thing, so a mail client (MUA) should only be used to read e-mails and not worry about how to fetch e-mails nor how to compose and send them. I do agree. Let me come to that in my next blog post. For this blog post let me introduce configuring Mutt to fetch, read and send e-mails.

As like any free software, the standard way to build Mutt is to run sh configure && make && sudo make install. But, to configure Mutt with SMTP and IMAP support, the following arguments need to be passed to the configure script.

sh configure --enable-imap --with-ssl --enable-smtp --enable-hcache && \
make && \
sudo make install

Setting up Mutt and IMAP

Now that Mutt has been installed, we'll set up a minimum configuration to effectively use Mutt with IMAP.

The Mutt configuration file is by default stored in your home directory as .muttrc. So let us begin by creating this file, and I'll explain the use of each line in the configuration file through comments. Like many Unix configuration files, # is recognized as the comment character in muttrc also.

# Instead of beginning from scratch, start with the installed configuration
source /usr/local/etc/Muttrc

# Inform Mutt where to fetch your mails from?
# If the server (specified by hostname) doesn't support SSL, change imaps to imap below
set spoolfile = imaps://username@hostname:port/INBOX

# Set the folder so as to use shortcuts while specifying draft and sent folders
# If the draft and sent folders are below the INBOX directory, append INBOX below
set folder = imaps://username@hostname:port/

# Inform Mutt where to save a copy of the outgoing mail
# Typically for Exchange mail, the sent folder is "Sent Items" parallel to the INBOX folder!
set record = "=Sent Items"

# Set the drafts folder
set postponed = "=Drafts"

# Tell Mutt which folders to query for new mails
# The following says only the $spoolfile folder (INBOX) needs to be queried
mailboxes !

Setting Mutt with SMTP

Starting with version 1.5.x, Mutt adds support for SMTP as well. This means that you don't have to configure Sendmail to relay local mails to remote server, nor you need to install a light-weight MTA like MSMTP.

# Tell Mutt how to send mails
# If your SMTP server doesn't support SSL or TLS, use smtp over smtps
# If your SMTP server doesn't support authentication, remove the username@
set smtp_url = smtps://username@hostname:port/

Putting it altogether

That's it, you're done configuring Mutt with IMAP. But, with the above configuration Mutt will fetch the mails from the server everytime which can be slow depending upon the server and the number of messages on the server. Thankfully Mutt can be configured to use a local cache for speeding up things. If you remember while configuring Mutt I had passed --enable-hcache to the configure script. This option builds Mutt with support for caching. Add the following to the Mutt configuration file and you're done.

# Cache the headers locally under $HOME/mail/headers folder
# Create this folder manually before starting Mutt
set header_cache = "~/mail/headers"

# For better performance cache the message body as well
# Create this folder manually before starting Mutt
set message_cachedir = "~/mail/messages"

Additional goodies - using an LDAP address book

If you're using Mutt in an organization where the address book is available through LDAP, then you can ask Mutt to query it for addresses. Unfortunately Mutt by itself doesn't come with querying remote address books, so I have written a small shell procedure that wraps ldapsearch which is bundled with OpenLDAP. You can download and build the software yourself or grab the pre-built package from here.

Once OpenLDAP is installed, you can download my shell script and use it with Mutt. Here's how you can use it assuming you have installed my script under some directory which is in $PATH:

# Substitute $BASEDN, $HOST and $PORT with your organization's LDAP settings
set query_command = "ldap_query -b $BASEDN -h $HOST -p $PORT %s"

When composing a mail, you can hit Control-T (^T) to query the LDAP server.

Hope that was useful. In the upcoming posts I'll write about configuring Mutt with multiple accounts.


  • 1
Thanks for the post. Will give it a spin on my work laptop.

going retro?

(Anonymous)
Don't you think that it's a bit of a throwback to be going back to the command line when the world (and even Linux) is finally moving away from it?

-The Practical Idealist

Been using mutt for ages. The one warning that needs to be given is despite the header cache feature in 1.5.x, mutt is incredibly slow with maildir on FS that tend to bog down as the number of entries in a directory increases. The problem can be mitigated by delegating the FS operations to an IMAP server like dovecot and accessing mutt via dovecot.

Was looking around for a way to use LDAP on our exchange and found this. Perfect! Thanks.

- Sandip

  • 1
?

Log in