How to set up Gmail Mutt and OfflineIMAP with multiple accounts part 3

This shall be an in depth look at how to set gmail with mutt and offlineimap using multiple gmail accounts.

This third part is how to set up mutt.

Part 1: Gmail
Part 2: offlineIMAP
Part 3: mutt

Setting up msmtp

Mutt is an interface for browsing mail. You can create mail in the program but mutt needs another program like msmtp to actually send the mail. In your home directory, we’ll need to create the file .msmtprc to specify the accounts from which we will be sending mail. Let me recall what accounts we have:

Accounts used under


Accounts used under


I’m mostly going to steal the config found in the Arch Linux Wiki.

In .msmtp we’ll start with our personal account:

account personal
port 587
protocol smtp
auth on
password mypassword
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

That last line I don’t know anything about. I know it works for me, but if it doesn’t for you check your files in that same directory or /usr/share/ca-certificates or check out this page.

Now, since we are also using that gmail account to send mail from we put into .msmtprc

account school : personal

Essentially, that says inherit all defaults form the account personal but change the from field to

It should be easy enough to figure out the rest of your .msmtprc file.

Setting up Mutt

By default, mutt will look for $HOME/.muttrc or $HOME/.mutt/muttrc files. I like to use the latter because I have a few other mutt files that I’d like to keep together. Ok, let’s see what we need to put in our muttrc file.

First, we’ll need to specify the type of mail system we are using. As we set up with offlineIMAP we use Maildir

set mbox_type=Maildir

Now we need to say where we keep the mail:

set folder=$HOME/.mail

Now, it might make sense to visit that folder to see how our mail is stored. Inside $HOME/.mail, we should have two folders, net and personal. Inside each of those two folders there are all the gmail mailboxes with their own folders: INBOX,[Gmail].All Mail,…,personal (and any other labels that we may have). Each of these folders is a mailbox.

So now we want to specify where mutt should start when it opens up

set spoolfile=+"personal/[Gmail].All Mail"

I’ve written this relative to the folder specified earlier and I put it in quotes because it has some weird characters and a space.

Now, it’s called spoolfile because it’s supposed to be like a dumping ground where things will get moved from later. However, I let gmail do all my filtering and labeling so I don’t want anything to move be default:

set move=no

It is supposed to improve speed by making a cache of the headers:

set header_cache=$HOME/.mail/.hcache

Naturally, you can put this wherever you want.

Here’s a bunch of things that you’ll want to put in, they should all make sense:

set realname='Miggy Smith'
set sendmail="/usr/bin/msmtp"
set envelope_from=yes
set edit_headers=yes

I don’t edit my headers when I’m writing my emails, but I like to be able to see them. I like vim for writing my emails

set editor="vim +/^$"

This will launch vim with the cursor at the first blank line (so right after the header).

At this point, we should be good to go, but here are a few things that you shouldn’t have to live without.

Here’s what I think is the best sorting algorithm:

set sort=threads
set sort_aux=reverse-last-date-received

To look at mail in different folders, we can browse for the folders by using ‘c’ but we can do this better by setting up some mailboxes. We will get a list of them in mutt by pressing ‘y’ and mutt will say if they have new mail or not. To set up mailboxes, we just specify the folders in muttrc:

mailboxes +"personal/[Gmail].All Mail" +personal/personal +personal/school +net/INBOX

Obviously, set up whichever ones you want. (Okay so that looks weird above but those are just single spaces after each folder name…wordpress is trying to make it look pretty)

Lastly, if we are going to be in a certain folder/mailbox, we are likely going to want to send from a corresponding account.

We can set up commands like this in muttrc:

macro generic "1" ":set"
macro generic "2" ":set"

So that if we type the escape key and then number 1 it will set the from field to Then if you write a mail, it will use that as the from field.

But we can also do this automatically depending on what folder we are in:

folder-hook personal/personal set
folder-hook personal/physics set
folder-hook personal/school set
folder-hook net/* set

(Again wordpress is trying to make the above look pretty…those are just single spaces)

Further, when replying to emails, you’ll probably want to reply from the account they sent to you. Do this with reverse_name, but you’ll also have to tell mutt your default account and other accounts it may use:

set reverse_name=yes

All right. Enjoy gmail mutt and offlineIMAP.

Part 4 will be a few more tips and tricks when I get around to it.

Tags: , , , ,

12 Responses to “How to set up Gmail Mutt and OfflineIMAP with multiple accounts part 3”

  1. Steve K. Says:

    Great stuff.

    Btw, there’s a patched version of mutt with SMTP built in . Not a big deal in and of itself, but it also comes with a sidebar that has a navigable list of your folders, with unread mail counts (and I think some other nifty tricks, although I haven’t explored its capabilites much yet).

  2. John C. McCabe-Dansted Says:

    Hi, the maxage and maxsize commands have just (2009-Aug-16) been added to imapoffline. If you get the latest version from git, you can set your Account section to look something like:

    [Account personal]
    localrepository = local-personal
    remoterepository = remote-personal
    maxage = 30
    maxsize = 50000

  3. Zack P. Says:

    This was just what I was looking for–Thanks for the help!

  4. Chuck Smith Says:

    Love the How-to! Worked like a charm. I have one question: How do you get the folder index to display on the left side of the window? When I had mutt configured to connect directly to imap at gmail, the index was populated with folders, but not with the offlineimap setup.

  5. Wesley Says:

    Great post, it helped me plenty! To clarify the maxage setting John commented on, in .offlineimaprc under the [Account] section: “maxage = 30” only syncs down mails no older than 30 days. As it’s applied as an IMAP filter server side, it’s super fast and a time, bandwidth and sanity saver if you setup existing accounts with more email than you care to sync.

  6. The Command Line Challenge. | Oldboy Says:

    […] in Gmail, but that’s a topic for another post. I find mutt even more powerful. Here’s a guide to keep mutt synchronized with your gmail […]

  7. The Command Line Challenge « darryn van tonder Says:

    […] can do in Gmail, but that’s a topic for another post. I find mutt even more powerful. Here’s a guide to keep mutt synchronized with your gmail […]

  8. 挑战命令行—完全使用命令行操作LINUX Says:

    […] can do in Gmail, but that’s a topic for another post. I find mutt even more powerful. Here’s a guide to keep mutt synchronized with your gmail […]

  9. Guía de supervivencia para la línea de comandos en Linux | CyberHades Says:

    […] mutt (aquí una guía de como usarlo con […]

  10. Linux 命令行终极挑战 | 极地 EA163 Says:

    […] Gmail 能做的一切。我个人的感觉是 mutt 比 Gmail 更强大。这里有一个 教程 关于如何同步 mutt 和你的 Gmail […]

  11. Muttguy Says:

    This is the right guide to get people started with mutt! The concise and clear explanations are very helpful. Thank you!

  12. Servicios Web Gratis » Guía de supervivencia para la línea de comandos en Linux Says:

    […] mutt (aquí una guía de como usarlo con […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: