Using mutt for IMAPS

Last update: 2007-10-18

mutt: The text-based mail client

mutt is a highly configurable mail client for the console. It uses the ncurses library to display its output. mutt provides security due to its inlcuded support for SSL secured connections for the IMAP protocol. We'll see how to prepare mutt for the daily use and learn some things about mail protocols.

IMAP and IMAPS

IMAP stands for Internet Message Access Protocol and is used to provide central access to your mails without having to download them. The mail client only has to fetch some general information, like the email subject, to offer a list of messages. Especially mobile devices have a profit from, because it reduces data redundance. Furthermore it's possible to have your emails stored on a central server, ordered by mail processors into different subdirectories.

IMAPS is the SSL secured variant of IMAP, and should be prefered when possible.

Installing the required components

Before we install mutt, we have to configure it properly. As we need security, we've to append the following line to the configure script:

--with-ssl --enable-imap

Compile and install it as root. Gentoo users add the USE flags ssl and imap. Also install a SMTP client, e.g. msmtp. Now we'll create configuration files fitting to your needs.

Configuration file for mutt

For your daily work with mutt and your IMAP account, we create a config file which mutt processes before starting. The following lines are not obligatory, but recommend for comfort:

set pager_context=1
set pager_index_lines=6
set menu_scroll
set pgp_verify_sig=yes
set status_on_top
set sort=threads
unset allow_8bit

set status_format=" %r %b %f %n      Del %d      Msgs %m %l %> (%P)"
set pager_format="%-10.10i %[!%a %b %d %R]"
set date_format="!%H:%M %a %d %b     "
set index_format="%4C %Z %[%b%d] %-15.15F %s"
set folder_format="%2C %t %8s %d %N %f"

Now we have to define the IMAP account information:

set spoolfile=imaps://[user]@[imap-server-domain.com]/INBOX
set folder=imaps://[imap-server-domain.com]/
set imap_pass="secret"

Adopt the lines accordingly.

We're now able to contact the server and to check the mails. But we also need the possibility to send emails to a relay. So we add the underlying lines.

# Set the folder to save outgoing mails.
set record="$HOME/mail/sent"
# Your prefered editor.
set editor="vim"
# SMTP client
set sendmail="/usr/bin/msmtp"

set from="your_mail_address"
set realname="your_name"

# In case you want a signature to be appended:
set signature="path_to_sig"

set use_from=yes
set envelope_from=yes

# In case you need a specific header (e.g. your JID):
my_hdr Jabber-ID: anyone@jabber.org

# Cut the header information and show the full header by pressing 'h'.
bind pager h display-toggle-weed
ignore *
unignore  Date To From: Subject X-Mailer Organization User-Agent
hdr_order Date From To Subject X-Mailer User-Agent Organization

# Add some colors
color error red default
color header cyan default none
color header red default Subject:
color header cyan default From:
color header cyan default Content-
color hdrdefault cyan default
color index white default none
color indicator green default
color markers red default
color message white default
color normal white default
color search blue default
color signature blue default
color status green default
color tilde white default
color tree green default
color underline white default
color attachment blue default
color quoted blue default
color quoted1 blue default
color quoted2 cyan default
color quoted3 blue default
color quoted4 cyan default
color quoted5 blue default

Save this file in your home directory as .muttrc.The configuration of mutt has been finished. Now we've to configure msmtp.

Configuration file for msmtp

Finally we create a config file for msmtp to be able to send emails to a relay.

# Account name (for single account use 'default')
account default
# Set the relay host
host imap-server-domain.com
tls on
connect_timeout 300
protocol smtp
from your_mail_address
# If required, we add information to authenticate
auth on
user your_user_name
password your_secret_password

Save this file as .msmtprc in your home directory.

Have fun with your new mail environment.