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 personal@gmail.com:
- personal@gmail.com
- student@school.edu
- student@physics.school.edu
Accounts used under net@gmail.com
- net@gmail.com
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
host smtp.gmail.com
port 587
protocol smtp
auth on
from personal@gmail.com
user personal@gmail.com
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 student@school.edu we put into .msmtprc
account school : personal
from student@school.edu
Essentially, that says inherit all defaults form the account personal but change the from field to student@school.edu
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 from=personal@gmail.com
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 from=student@physics.school.edu"
macro generic "2" ":set from=personal@gmail.com"
So that if we type the escape key and then number 1 it will set the from field to student@physics.montana.edu. 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 from=personal@gmail.com
folder-hook personal/physics set from=student@physics.school.edu
folder-hook personal/school set from=student@school.edu
folder-hook net/* set from=net@gmail.com
(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
set from=personal@gmail.com
alternates student@school.edu|student@physics.school.edu|net.gmail.com
All right. Enjoy gmail mutt and offlineIMAP.
Part 4 will be a few more tips and tricks when I get around to it.
Tags: email, gmail, linux, mutt, offlineimap
June 12, 2009 at 1:12 am |
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).
August 31, 2009 at 10:53 pm |
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
November 19, 2009 at 1:15 pm |
This was just what I was looking for–Thanks for the help!
February 15, 2010 at 6:09 pm |
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.