Tags

, , , , , , , , ,

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_user unset imap_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.

About these ads