Consolify your Gmail with MUTT
"All mail clients suck. This one just sucks less."
- Michael R. Elkins, ca 1995
Mutt is one of the best email clients ever created.
The only disadvantage is that it is text based only, and that doesn't help in the Icons/Windows/Tablet era. In fact, it prevents many people from using it as their default email application. Mutt is, however, a very powerful email client with many features that are not included in other GUI clients. If you are one of those people who appreciate the simplicity and versatility of the console environment, whether it's on your laptop, desktop PC or the Raspberry Pi, you'll love Mutt at the first sight if it hadn't already happened.
If you've never heard of Mutt before, I will show you how to get Mutt up and running with your Gmail provider through its IMAP API and provides some key-bindings to make the daily use easier.
We will also learn to receive and send email with the mighty Mutt.
Mutt is a Mail User Agent (MUA), and was written to view mail. It was not written to retrieve, send, or filter mail. It relies on external programs to do those tasks. But recently it has become possible to receive and sending mails trough Gmail.
Some of Mutt's features include:
- colour support
- message threading
- MIME support (including RFC2047 support for encoded headers)
- PGP/MIME (RFC2015)
- various features to support mailing lists, including list-reply
- active development community
- POP3 and IMAP support
- full control of message headers when composing
- support for multiple mailbox formats (mbox, MMDF, MH, maildir)
- highly customizable, including keybindings and macros
- change configuration automatically based on recipients, current folder, etc.
- searches using regular expressions, including an internal pattern matching language
- Delivery Status Notification (DSN) support
- postpone message composition indefinitely for later recall
- easily include attachments when composing, even from the command line
- ability to specify alternate addresses for recognition of mail forwarded from other accounts, with ability to set the From: headers on replies/etc. accordingly
- multiple message tagging
- reply to or forward multiple messages at once
- .mailrc style configuration files
- easy to install (uses GNU autoconf)
- compiles against either curses/ncurses or S-lang
- translation into at least 20 languages
- small and efficient
- It's free! (no cost and GPL'ed)
Download and install Mutt with this command:
sudo apt-get install mutt
The default settings are fine to start with. Yet, if you want to alter something, just put it in the configuration file that controls it all:
You can find the syntax for these configurations in the MuttGuide.
Setting up IMAP
To be able to access your mail from Mutt, we have to configure it to connect to Gmail's IMAP server.
Let's create/edit the
.muttrc configuration file (Note the dot - . - before the filename - this sets Mutt configuration file as "hidden"):
vim .muttrc #you can use any other editor - it doesn't have to be vim
First, you have to tell Mutt who you are. Put the following in your configuration file:
set from = 'firstname.lastname@example.org' set realname = 'Your Name'
Mutt has to know as well where your Gmail mailbox is and what your password is (You can safely put your password in the file, but I HIGHLY RECOMMEND USING THE 2-STEP VERIFICATION).
set imap_user = 'email@example.com' set imap_pass = 'yourpassword'
When running Mutt for the first time, a certificate will be downloaded and you will be asked if you want to keep it. Of course you want it; just type
The following configuration lets Mutt recognize your Gmail folders (labels) and your local folders.
# REMOTE GMAIL FOLDERS set folder = 'imaps://imap.gmail.com:993' set spoolfile = '+INBOX' set postponed ='+[Google Mail]/Drafts' set trash = '+[Google Mail]/Trash' set any_label = '+[Google Mail]/any_label'
As sent messages go to your Sent Mail folder on the Gmail server by default, nothing has to be done with it.
# LOCAL FOLDERS FOR CACHED HEADERS AND CERTIFICATES set header_cache =~/.mutt/cache/headers set message_cachedir =~/.mutt/cache/bodies set certificate_file =~/.mutt/certificates
Now, we can create the two folders mentioned above -
~/.mutt/cahce, however, on first run Mutt will create them automatically.
Setting up SMTP
To allow Mutt send mail from our machine, we must set access to Gmail's SMTP server. In the same file add:
# SMTP SETTINGS set smtp_url = 'smtp://firstname.lastname@example.org:587/' set smtp_pass = 'yourpassword' # use the same password as for IMAP
Securing Mutt Session
To prevent some annoyances with the session, add to your configuration file the following:
# SECURING set move = no #Stop asking to move read messages to mbox! set imap_keepalive = 900
You can also set some keybindings to simplify your Mutt usage. Here's and example, that allows changing folders with keys:
bind editor noop macro index gi '=INBOX' 'Go to inbox' macro index ga '=[Google Mail]/All Mail' 'Go to all mail' macro index gs '=[Google Mail]/Sent Mail' 'Go to Sent Mail' macro index gd '=[Google Mail]/Drafts' 'Go to drafts'
In order to make those work, you have to set the labels visible in your IMAP Gmail settings (Settings -> Labels).
For more information on the keybindings, head to MuttGuide/Macros.
And if you want to see my configuration file, go here: Bubbl Muttrc. The config is constantly growing.
With all the basic things configured, save the
.muttrc file in your Home directory. To be sure that only your username can access the file you'll have to give the file a proper permission:
chmod 700 .muttrc
And we're done! You can now run Mutt from console by simply typing
mutt and enjoy consolified Gmail.
These are just the basics of Mutt. You can do much more with it. Check my configuration file on github to get more out of your Mutt.
Apart from the official MuttGuide, there are great guides to get you started with using and customizing Mutt:
- My First Mutt
- The Woodnotes Guide to the Mutt Email Client
- Learning Mutt
- User Config File Examples
- The Homely Mutt (an amazing write up on which I've based my configuration a bit)
Additional applications that might be worth trying are urlview and muttprint (these are not associated with Gmail though):
sudo apt-get install urlview muttprint muttprint-manual mutt-patched w3m
urlview - extracts urls from text and allows you to view in a program of your choice
[muttprint](https://muttprint.sourceforge.net/) - Printing those emails in a lovely format
muttprint-manual - The manual to tell you how to make those prints even prettier
mutt-patched - Folder view for mutt