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
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.