Configure Terminal Email Client: Neomutt
This post documents how I set up the terminal based email client (Neo)mutt
# Background
Mutt (opens new window) or Neomutt (opens new window) is a terminal based email client. It is a well received terminal application primarily for Linux systems. Although there are many great Email applications with lood-looking graphic designs in various Linux distros (e.g. Thunderbird which is pre-installed in my Manjaro Distro), many people would still prefer an old-school terminal based application for the emails. The reasons people may choose a terminal based applications over a GUI applications are:
- Speed: Without loading all graphic components, terminal based application usually has better performance and is more responsive.
- Configurability: Many terminal based applications are usually very configurable. And the configurations are just kept jin one or a few dot files, which makes it extremely easy to sync among different machines.
- Better workflow integration: When working in a Linux world, one likely spends most of the time in the terminal. Using a terminal based application makes the workflow more fluent and natural. And by making the shortcuts the same logic as the shell application and text editor, one would be very fast in those applications without ever leaving the keyboard.
When it comes to the emails, Mutt/Neomutt is pretty much the only choice of the terminal based Email application.
# Installation
Just like Vim and Neovim, Neomutt is more modern version of Mutt. To install Neomutt, simply use your system's package manager. For example, for Arch based system, simply do:
pacman -S neomutt
# Configuration
I kept my Neomutt configuration in ~/.config/neomutt/
. The entry point is the muttrc file. Below is the folder structure.
├── accounts
│ └── yahoo
├── colors
├── mailcap
├── mappings
├── muttrc
└── settings
- muttrc: This is the entry point of all configuration files, similar to init.vim for VIM configuration. It will simply source the rest of the configuration files.
- accounts: You could have multiple email accounts configured in neomutt. The folder hosts account specific configurations such as the corresponding email servers, login credentials, email Folders etc.
- mailcap: This file is used to define the applications to use for various attachments in emails. In modern emails, it is not just the plain texts. More often, an email will contain html, pictures, PDFs, etc. The mailcap file will configure what applications to use for dealing with these non-text files contained / attached in emails.
- mappings: Customized key mappings for neomutt. While neomutt's default key mappings are already great and straightforward, I would prefer to have a few more keystrokes that would operate in a similar way as VIM does.
- settings: General behaviors of neomutt are configured in this file.
- colors: And last but not the least, color schemes can be defined for the mail box, email headers, bodies and more.
# Main Configuration muttrc
A simple entry point muttrc file could look like this:
source ~/.config/neomutt/settings
source ~/.config/neomutt/colors
source ~/.config/neomutt/mappings
# Connect to An Email Account
Depending on the email provider, the way you need to specify your account information is a bitter different. The main things need to be set include:
- Email servers: This includes both receiving and sending servers. The common server protocol is IMAP for receiving and SMTP for sending. Below is an example of Yahoo emails server information
set imap_user = "myusername@yahoo.com"
set folder = "imaps://imap.mail.yahoo.com:993"
set spoolfile = "+INBOX"
set record = "+Sent"
set trash = "+Trash"
set postponed = "+Draft"
set smtp_url = "smtp://myusername@smtp.mail.yahoo.com:587/"
mailboxes =INBOX =Sent =Trash =Draft
You would also need to supply your email credentials in the setting. Some email provider would require a more secured way to access the mail boxes. For example, Yahoo mail requires to use a randomly generated password for any third party email client. You could specify the password directly in the configuration file. But you could also use the file encryption applications such as gpg (opens new window) to encrypt the password. The way to set your email password is as follows:
set smtp_pass = 'mypassword'
set imap_pass = 'mypassword'
# General Behavior: settings
For general settings, it is all about personal preference. A few things that you could set as your default includes:
unset confirmappend # No additional prompt asking for confirmation
set quit # No additional prompt asking for confirmation
unset mark_old # Only mark read/new
set beep_new # Bell on new mails
set pipe_decode # strip headers and eval mimes when piping
set thorough_search # strip headers and eval mimes before searching
# Key mappings: mappings
I prefer the key mappings to be similar to what I have for VIM.
# General rebindings
bind attach <return> view-mailcap
bind attach l view-mailcap
bind editor <space> noop
bind pager c imap-fetch-mail
bind index G last-entry
bind index g noop
bind index gg first-entry
bind pager,attach h exit
bind pager j next-line
bind pager k previous-line
bind pager l view-attachments
bind index D delete-message
bind index U undelete-message
bind index L limit
bind index h noop
bind index l display-message
bind browser h goto-parent
bind browser l select-entry
bind pager,browser gg top-page
bind pager,browser G bottom-page
bind index,pager,browser d half-down
bind index,pager,browser u half-up
bind index,pager R group-reply
bind index \031 previous-undeleted # Mouse wheel
bind index \005 next-undeleted # Mouse wheel
bind pager \031 previous-line # Mouse wheel
bind pager \005 next-line # Mouse wheel
bind editor <Tab> complete-query
# sidebar mappings
bind index,pager \Ck sidebar-prev
bind index,pager \Cj sidebar-next
bind index,pager \Co sidebar-open
bind index,pager \Cp sidebar-prev-new
bind index,pager \Cn sidebar-next-new
bind index,pager B sidebar-toggle-visible
# global index and pager shortcuts
bind index,pager @ compose-to-sender
bind index,pager D purge-message
bind index <tab> sync-mailbox
bind index <space> collapse-thread
# Email completion bindings
bind editor <Tab> complete-query
bind editor ^T complete
# Press A to add contact to Khard address book
macro index,pager A \
"<pipe-message>khard add-email<return>" \
"add the sender email address to khard"
### Shortcuts
macro index,pager U "<enter-command>set pipe_decode = yes<enter><pipe-message>urlview<enter><enter-command>set pipe_decode = no<enter>""view URLs"
# Color scheme: colors
Color scheme is always the fun part. Below is my color scheme.
# Header colors:
color header blue default ".*"
color header brightmagenta default "^(From)"
color header brightcyan default "^(Subject)"
color header brightwhite default "^(CC|BCC)"
mono bold bold
mono underline underline
mono indicator reverse
mono error bold
color normal default default
color indicator brightyellow default # currently selected message. default makes bar clear, disabled arrow to save space.
color sidebar_highlight red default
color sidebar_divider brightblack black
color sidebar_flagged red black
color sidebar_new green black
color normal brightyellow default
color error red default
color tilde black default
color message cyan default
color markers red white
color attachment white default
color search brightmagenta default
color status brightyellow black
color hdrdefault brightgreen default
color quoted green default
color quoted1 blue default
color quoted2 cyan default
color quoted3 yellow default
color quoted4 red default
color quoted5 brightred default
color signature brightgreen default
color bold black default
color underline black default
color normal default default
color body brightred default "[\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+" # Email addresses
color body brightblue default "(https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+" # URL
color body green default "\`[^\`]*\`" # Green text between ` and `
color body brightblue default "^# \.*" # Headings as bold blue
color body brightcyan default "^## \.*" # Subheadings as bold cyan
color body brightgreen default "^### \.*" # Subsubheadings as bold green
color body yellow default "^(\t| )*(-|\\*) \.*" # List items as yellow
color body brightcyan default "[;:][-o][)/(|]" # emoticons
color body brightcyan default "[;:][)(|]" # emoticons
color body brightcyan default "[ ][*][^*]*[*][ ]?" # more emoticon?
color body brightcyan default "[ ]?[*][^*]*[*][ ]" # more emoticon?
color body red default "(BAD signature)"
color body cyan default "(Good signature)"
color body brightblack default "^gpg: Good signature .*"
color body brightyellow default "^gpg: "
color body brightyellow red "^gpg: BAD signature from.*"
mono body bold "^gpg: Good signature"
#mohttps://neomutt.org/code/config_vars.htmlno body bold "^gpg: BAD signature from.*"
color body red default "([a-z][a-z0-9+-]*://(((([a-z0-9_.!~*'();:&=+$,-]|%[0-9a-f][0-9a-f])*@)?((([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)(:[0-9]+)?)|([a-z0-9_.!~*'()$,;:@&=+-]|%[0-9a-f][0-9a-f])+)(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?(#([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?|(www|ftp)\\.(([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?(:[0-9]+)?(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?(#([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?)[^].,:;!)? \t\r\n<>\"]"
# Default index colors:
color index yellow default '.*'
color index_author brightmagenta default '.*'
color index_number blue default
color index_subject cyan default '.*'
# For new mail:
color index brightyellow default "~N"
color index_author brightred default "~N"
color index_subject brightcyan default "~N"
color progress black cyan
# Last Words
Neomutt can be a bit tedious to configure. Fortunately, there are a lot of people out there willing to share their dot files. For example, my configurations are largely based on Gideon Wolfe's Configuration here (opens new window).
Youtuber Luke Smith also made a wizard for neomutt which can be found here: LukeSmithxyz/mutt-wizard (opens new window)