An efficient command-line email client
Command Line – Mutt
![© Lead Image © Devilpup, Fotolia.com © Lead Image © Devilpup, Fotolia.com](/var/linux_magazin/storage/images/issues/2021/245/mutt-for-beginners/po-21556-fotolia-devilpup_fotolia-hundeschnauze_resized.png/783214-1-eng-US/PO-21556-Fotolia-Devilpup_Fotolia-Hundeschnauze_resized.png_medium.png)
© Lead Image © Devilpup, Fotolia.com
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.