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.

muttThe 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.

Features

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)pager
  • 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)

Installation (Debian)

Download and install Mutt with this command:

sudo apt-get install mutt

Configuration

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: ~/.muttrc.

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:

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).

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 Yes.

Folders/Labels Access

The following configuration lets Mutt recognize your Gmail folders (labels) and your local folders.

As sent messages go to your Sent Mail folder on the Gmail server by default, nothing has to be done with it.

Now, we can create the two folders mentioned above – ~/.mutt and ~/.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:

Securing Mutt Session

To prevent some annoyances with the session, add to your configuration file the following:

KeyBindings

You can also set some keybindings to simplify your Mutt usage. Here’s and example, that allows changing folders with keys:

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.

Additional Configuration

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:

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 – 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
  • Darien

    really a great thing! Since I got the Raspberry, I wanted to use it only in text mode, and this tutorial helps me to get my mail working! really great!
    I see toe confs on your github change all the time, I hope soon there’ll be a more or less final version, as I wanted to test it. btw, what’s the offlineimap you have there? you didn’t cover it in the post?
    and one more question, do you know any Twitter command line client?
    Thanks

    • thanks Darien!
      the config is – more or less – done. I’m happy with what I’ve created.
      the amount of files… it’s just that I wanted a clear config, all the files are just holding certain parts of it, like key bindings, colours, etc.
      it’s fun to configure, even if it’s done with the help of tutorials (they’re for this purpose), you learn a lot of things.
      as for the offlineimap – it’s a tool to fetch mailboxes onto your hard drive. I find it convenient, especially if I don’t have access to the Internet. and you don’t have to wait for the mail to fetch any time you open a mailbox. it’s already there, indexed, waiting for you to get it. of course, you can use imap synchronization, but… as I said, it’s better to be synchronized.
      mutt-notmuch is an indexing tool for offlineimap.
      I won’t cover them, as there’re plenty of great tutorials out there (I wrote about Mutt to get some people to know it), like e.g. this one: http://stevelosh.com/blog/2012/10/the-homely-mutt/#installing-offlineimap

      as for Twitter client, I’m using turses. it’s just great. https://github.com/alejandrogomez/turses

      check the links out and I wish you luck with the mighty Mutt!

  • Hi, do you know how to sync the mail (gmail) using offlineimap? The connection is always disconnected after a downloading some mail. Or maybe you know any other way to download all email from gmail? Thanks before :)

    • yes, I do know.
      too much to write about it in a comment, check out a great tutorial: http://stevelosh.com/blog/2012/10/the-homely-mutt/#configuring-offlineimap
      just omit the python file (and notmuch if you don’t want indexing) and it should work perfectly.
      if in doubt, ask

      • I’ve been there but the problem still occured. I only get 197 mails until it disconnected from server and return “too many read 0”. I’ve been searching about it too, people said that it’s some kind of limitation from google. That’s why I asked in here, maybe you have a workaround for this problem.

        • oh, that’s the problem!
          stupid questions, you set IMAP on google?
          if not:
          go to Settings >> Forwarding and POP/IMAP
          enable IMAP access
          set Auto-Expunge on
          Folder Size Limits >> Limit IMAP folders to contain no more than this many messages: 1,000

          AND
          in your offlineimaprc file
          change all the [Gmail] labels to [Google Mail]. in fact, [Gmail] is not correct and creates a separate label. this might be the problem. then, delete all to contents of your mail folder as well as .offlineimap folder contents and re-run offlineimap.

          should work fine. google doesn’t limit me at all.
          the probem might also be that google thinks you spam it. try as well using two-step verification, http://www.google.com/intl/en-GB/landing/2step/, a separate password for mutt might be useful and helpful.

  • I already tried your solution but the error still persist. And when I change all the [Gmail] labels to [Google Mail] gmail create new label for it so I thought the real label is [Gmail].
    Here is the screenshot of the error:
    http://i41.tinypic.com/vio65l.png

    And this is my offlineimap configuration:
    http://dpaste.com/hold/1447074/

  • Great tutorial, got Mutt up & working in no time!!!
    Really happy about that.
    Thank you.

  • Bernd

    Hi, using mutt with account xxx@outlook.de. No problem so far. I want to use mutt for several outlook.de accounts – dont have any clue how to configure mutt. Any ideas?

  • Grazfather x

    Useful article. Maybe your CMS changed or something, because you need to change all the & gt; aka >, etc. back to proper symbols.

    • thanks for pointing this out. I’ve changed recently plugin that handles code pretifying and forgot to check all the older posts. will update this as sonn as possible!

      • Grazfather x

        Wow quick reply! Thanks a lot for this.

  • suv_f430

    Hi Bart
    I have setup the muttrc file just the way you have mentioned, also enabled IMAP on gmail
    When I run mutt, it says “login failed”
    After filling in the .muttrc file I had errors on Line 6 of #REMOTE GMAIL FOLDERS so I have commented it out

    • Hi, the authentication issue might come from the fact that you used clear text password, you should rather use one time application code created from your google account dashboard, this should work without issues. As for the folders to sync, there moght be different IMAP folder paths than I specified in git repo, unfortunately, I’ve not used mutt for some time now, so am not sure if there were any changes. Guess you’d have to simply try this out ;)

      • suv_f430

        Hi Bart
        Thanks for the reply
        I had to change the settings so that the account will let me login through “less safer” apps
        Now mutt works, I can even send email through it
        Nice blog, cheers