An efficient command-line email client
Command Line – Mutt
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 from = "YOUR EMAIL ADDRESS" 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:
alias NICKNAME LONGNAME ADDRESS
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
(incl. VAT)
Buy Linux Magazine
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.
News
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.