This is a continuation of my effort to configure mutt. This post explains how to set up multiple IMAP and SMTP accounts using account-hook and folder-hook. All the configurations go into the file ~/.mutt/muttrc (or ~/.muttrc, if you prefer).
I am assuming that you want to setup mutt for two gmail accounts user1@gmail.com and user2@gmail.com with passwords pass1 and pass2, respectively. I am also assuming that you have saved the passwords in an encrypted file .passwd.gpg in the ~/.secret directory which contains the passwords in the second column as (refer to the previous post):
GMail1: pass1 Gmail2: pass2
as well as the corresponding signatures in user1.sig and user2.sig files in ~/.mutt directory.
With the above setup our ~/.mutt/muttrc now becomes:
#----------------------------------------- # ~/.mutt/muttrc settings for mutt 1.5.20 # Process the password file first #----------------------------------------- set my_tmp=`gpg -o ~/.secret/.tmp -d ~/.secret/.passwd.gpg` set my_pass1=`awk '/GMail1:/ {print $2}' ~/.secret/.tmp` set my_pass2=`awk '/GMail2:/ {print $2}' ~/.secret/.tmp` set my_del=`rm -f ~/.secret/.tmp` # #------------------------------------- # Account Hooks #------------------------------------- account-hook . 'unset imap_userunsetimap_pass' # unset first! account-hook 'imaps://user1@imap.gmail.com/' "\ set imap_user=user1 imap_pass=$my_pass1 " account-hook 'imaps://user2@imap.gmail.com/' "\ set imap_user=user2 imap_pass=$my_pass2 " # #------------------------------------- # Folders, mailboxes and folder hooks #------------------------------------- # Setup for user1: set folder="imaps://user1@imap.gmail.com/" mailboxes =INBOX =[Gmail]/Drafts =[Gmail]/'Sent Mail' =[Gmail]/Spam folder-hook 'imaps://user1@imap.gmail.com' " \ set folder=imaps://user1@imap.gmail.com/ \ postponed=+[Gmail]/Drafts \ record=+[Gmail]/'Sent Mail' \ smtp_url=smtps://user1@smtp.gmail.com \ smtp_pass=$my_pass1 \ signature=~/.mutt/user1.sig \ from='User One <user1@gmail.com> ' \ realname='User One' " # # Setup for user2: set folder="imaps://user2@imap.gmail.com/" mailboxes =INBOX =[Gmail]/Drafts =[Gmail]/'Sent Mail' =[Gmail]/Spam folder-hook 'imaps://user2@imap.gmail.com' " \ set folder=imaps://user2@imap.gmail.com/ \ postponed=+[Gmail]/Drafts \ record=+[Gmail]/'Sent Mail' \ smtp_url=smtps://user2@smtp.gmail.com \ smtp_pass=$my_pass2 \ signature=~/.mutt/user2.sig \ from='User Two <user2@gmail.com> ' \ realname='User Two' " # #------------------------------------- # Macros to make life easier #------------------------------------- macro index <esc>1 "y1<return><return>" # ESC+1 takes to first INBOX macro index <esc>2 "y5<return><return>" # ESC+2 takes to the second # #------------------------------------- # Mail-check preferences #------------------------------------- set timeout=60 #Check for mail every minute set mail_check=5 # # EOF
To configure other nifty options (e.g. color, editor) please refer to the previous post.

Juri
September 13, 2010 at 4:27 PM
Thank you,
you saved some of my time for the initial mutt configuration with mutt’s imap support.
Keep on.
kousik
September 14, 2010 at 7:21 PM
Glad that I could of some help.
rEnr3n
September 25, 2010 at 6:41 AM
I get twelve instances of “unset: unknown variable”
Any idea what this is? I have removed two lines of “signature=…” since I don’t have .sig files.
kousik
October 6, 2010 at 2:06 AM
Probably the spurious ‘unset’ command was being treated as a variable in my post:
account-hook . ‘unset imap_user
unsetimap_pass’Apologies!
Try it with the second ‘unset’ and let us know if it worked.
kousik
October 6, 2010 at 2:06 AM
I meant try it “without” the second ‘unset’!
Brian
November 20, 2010 at 1:03 AM
Thanks for the rundown. I have refined it a bit. It works perfectly. Of course, you’ll have to define key-bindings for the various folders if you unset imap_check_subscribed. The mailbox screen can be reached by typing c, ?, . Also, it isn’t necessary to set record since Gmail will automatically save sent messages to [GMAIL]/Sent. Although most of the text is wrapped in this reply, said text is actually one line.
account-hook . ‘unset imap_user ; unset imap_pass’
account-hook ‘imaps://user1@imap.gmail.com/’ set imap_pass = password
account-hook ‘imaps://user2@imap.gmail.com/’ set imap_pass = password
unset folder
mailboxes imaps://user1@imap.gmail.com
folder-hook ‘imaps://user1@imap.gmail.com’ “set folder = imaps://user1@imap.gmail.com ; set postponed = +[Gmail]/Drafts ; unset record ; set smtp_url = smtps://user1@smtp.gmail.com:587 ; set smtp_pass = ‘password’ ; set from = ‘User ‘ ; set realname = ‘User’”
mailboxes imaps://user2@imap.gmail.com
folder-hook ‘imaps://user2@imap.gmail.com’ “set folder = imaps://user2@imap.gmail.com ; set postponed = +[Gmail]/Drafts ; unset record ; set smtp_url = smtps://user2@smtp.gmail.com:587 ; set smtp_pass = ‘password’ ; set from = ‘User ‘ ; set realname = ‘User’”
kousik
November 26, 2010 at 7:19 PM
Hey Brian, thanks a lot!
You’re right about the ‘set record’ with GMail. Everything you mentioned should work perfectly. However, I just want to make a quick comment: you can set several variables with a single set command as mentioned in the text, that is,
and
are the same things.
Brian
November 20, 2010 at 1:10 AM
Ooops! Accounts can be reached by typing c, ?, TAB.
fau
January 27, 2011 at 5:41 AM
Actually there is better way to decrypt passwords on the fly (no temp unencrypted files, whitch can be left on disk)
source command will read stdin instead of file when followed by “|”
This is how I use it:
.secrets file:
set my_pass1=”pass1″
set my_pass2=”pass2″
muttrc:
source “gpg –textmode -d .secrets.gpg |”
kousik
February 1, 2011 at 2:35 AM
Hey, thanks! That was a nice tip!
Armando
March 31, 2011 at 8:26 AM
I think there is a mistake: for “set imap_user” the “=” is missing, right?
thnx,
A.
kousik
March 31, 2011 at 11:18 AM
Yes, you are absolutely right! Thank you!
-Kousik
tonybaldwin
September 26, 2011 at 3:44 AM
Okay, but how does this work if I set iceweasel (firefox in debian) to use mutt for mailto links
xterm -e mutt “$1″
can I choose which address I am sending from with the same esc-1, or esc-2 binding? Seem that will only go to the inbox.
Or would mutt give me the option for the From: field as it would for subject, etc.?
I currently have two muttrc files (one .muttrc, and one .guttrc, and have aliased gmx to mutt -F .guttrc, since that is gmx.com mail over imap, the first being for gmail over imap), but I haven’t figure out how to allow myself a choice with mailto links.
I had tried with
xterm -e read -p “gmail (mutt) or gmx (gmx)? ” mailprog;
$mailprog “$1″
but the xterm dies as soon as I enter my choice.
If I can use one muttrc for both accounts, as indicated here, I’m assuming this would simplify that.
kousik
October 4, 2011 at 10:41 AM
It’s a good feature to have. But I don’t know how it can be acheived. Please let me know if you found a solution. Thanks!
laustmcgregor
May 15, 2012 at 4:05 PM
Hi,
I had to replace:
macro index 1 “y1″ # ESC+1 takes to first INBOX
by:
macro index 1 “c?1″
Mutt doesn’t seem to know the “y” shortcut (mutt 1.5.21)
illuminated.co.uk
March 2, 2013 at 4:43 PM
I think this is among the most vital information for me.
And i’m glad reading your article. But want to remark on some general things, The web site style is perfect, the articles is really nice : D. Good job, cheers
don
May 6, 2013 at 3:53 PM
Can you go one with multiple POP3 accounts?