An efficient command-line email client

Command Line – Mutt

© Lead Image © Devilpup,

© Lead Image © Devilpup,

Article from Issue 245/2021

Mutt, a command-line email client, can do anything a desktop client can with less overhead and a smaller attack surface. Here's how to get started.

I subscribe to half a dozen forums for email distribution. Hardly a week goes by without one of them including a complaint about a desktop email client like KMail or Thunderbird. For many, the ultimate solution is to go back to simpler days and install Mutt [1]. Not only does the command-line interface give users full control over the settings, but Mutt's lack of a prepackaged rendering engine for web browsers or a JavaScript interpreter makes for a smaller attack surface. Another major advantage is its smaller, more consistent memory usage.

Mutt was first written by Michael Elkins in 1995. It was based on Elm, another popular command-line email client. Even today, Mutt remains very much a product of its time, often using other applications rather than adding functionality to its code. In particular, emails are composed in the external editor of your choice, while encryption depends on GnuPG [2]. In addition, Mutt is fully operable from the keyboard alone. You can tell a lot about Mutt's design philosophy by the slogan it has carried from its earliest days: "All mail clients suck. This one just sucks less." Efficiency and economy are very much its priority.

However, Mutt does require some setup. This article covers the minimal information you need to have Mutt up and running smoothly in a typical case. Should you have an atypical case, the man page for muttrc [3], Mutt's configuration file, lists dozens of possible alternative settings.

Basic Configuration

In deference to its age, Mutt is included in the repositories of most distributions. Preparing it for use consists primarily of editing its configuration files by adding commands and a few fields. To begin configuring, create the basic directories and the configuration file:

mkdir -p ~/.mutt/cache/headers
mkdir ~/.mutt/cache/bodies
touch ~/.mutt/certificates

The configuration file, muttrc, can have several locations that are detected automatically: ~/.muttrc, ~/.mutt/muttrc, and $XDG_CONFIG_HOME/mutt/muttrc, each with or without -MUTT_VERSION appended. Use touch to create the muttrc file with the path of your choice. For example, you can use:

touch ~/.mutt/muttrc

If you want to place muttrc in a nonstandard place, you can set the location by adding to muttrc the line:

source /path/to/other/config/file

Next, open the newly made muttrc in a text editor. As with most configuration files, start a line with # to add a comment, and use single or double quotation marks around an entry that contains spaces or special characters. Add the following lines to set Mutt's environment:

set realname = "NAME"
set use_from = yes
set envelope_from = yes
set editor = "EDITOR"
set charset = "CHARACTER-CODE"

If you are using an IMAP server, add:

set smtp_url = "EMAIL-ADDRESS:PORT/"
set smtp_pass = "PASSWORD"
set imap_pass = "PASSWORD"
set folder = "PATH:PORT"
set spoolfile = "+INBOX"
set record = +Sent
mailboxes = +INBOX
bind index  imap-fetch-mail

For folder, use the directory where messages are stored; spoolfile is where Mutt looks for incoming mail. The port is only needed if the folder is not local. The plus sign indicates that any subdirectories will be used as necessary.

Finally, set the mbox type and the structure for receiving messages as follows

set mbox_type=Maildir [or Mbox]
set folder=~/mail
set spoolfile=+/
set header_cache=~/.cache/mutt

where spoolfile should be the same as the spool file set for IMAP; header_cache stores email headers to increase the speed in which headers are displayed.

These lines of code will set up a bare-bones Mutt configuration with one or two additions for convenience. Before you go any further, send a message to check whether you have basic functionality. If you made any typos during setup, it will be easier to troubleshoot before you add more to your configuration.

Setting Passwords

Account passwords can be added with:

set my_pass = "PASSWORD"

The prefix my_ is used for any variables that you define. However, muttrc is unencrypted, so storing the password in it leaves your password visible to anyone. The simplest alternative is to enter your password each time you login. Better yet, set up encryption for it by adding

set my_pass = "PASSWORD"

to a new file. Other passwords can also be added to this file. Assuming that the email is encrypted with GPG, at the start of .muttrc, add the line

source "gpg -dq FILE |"

This line sets the variable for all password commands.

Contact Management

Mutt has two ways of setting up an address book. The first is to create aliases for each contact in a new file, one alias per line, with the structure:


The optional LONGNAME is the contact's full name. In Mutt, you use the NICKNAME to send an email to the contact. Pressing a when an address is entered in the To: field will also create a new file when aliases are set up in muttrc with the lines:

set alias_file = "PATH"
set sort_alias = alias
set reverse_alias = yes
source $alias_file

The alias file is where aliases are stored. The sort file determines whether aliases are listed by alias or address, while reverse_alias set to yes displays the long name if one is given. Adding the source allows Mutt to autocomplete when you enter an alias for the To: field. If the alias you enter is nonexistent, then a list of all aliases displays.

If you want a more sophisticated address book, you can use an external application such as Abook, GooBook, or Khard.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More