I've configured [mutt] so I can access several IMAP accounts and have it change the smtp server , signature and other stuff according to the account and folder I'm accessing.

See, I kind of abuse qmail's and [postfix's address extension capabilities] to avoid spam: in almost every mailing list I subscribe I have a different e-mail address. Since the "From" header of e-mail's sent to these lists are usually verified against its subscribers list, I've to setup a different "From" header to all these mailing lists. Instead of manually doing it, I've configured mutt so it does that for me in a delightful "automagical" way.

To avoid "relay denied" issues, I setup a different stmp command (mutt doesn't have a built-in smtp client) to every account I have. You will notice that I use a mix of ssh and [esmtp] to handle this.

You will also notice that I make a heavy use of SSH: to set up tunnels, to deliver e-mails and to forward the ports of e-mail servers inside intranets. I advise you to configure you SSH use public-key authentication and to learn how to use ssh-agent.


The configuration files


This is how I configure mutt:


.muttrc

# vide http://www.devshed.com/Server_Side/Administration/Mutt/print
# vide http://www.rohrbach.de/files/rc/.muttrc


###----------------------------------------------------------------------------
### Global settings
###----------------------------------------------------------------------------
source "~/.mutt/muttrc"

###----------------------------------------------------------------------------
### Local settings
###----------------------------------------------------------------------------
set xterm_set_titles="yes"
#set xterm_title="Mutt with %?m?%m messages&no messages?%?n? [%n NEW]?"
set xterm_title="Mutt %?b?[NEW mail in %b mailboxes]? %f %?m?%m messages&no messages?%?n? [%n NEW]?"
unset suspend

set spoolfile="~/Maildir/"

# local mailboxes go here
mailboxes =/INBOX/ =/OUTBOX/
mailboxes =/caughtspam/ =/spam/
mailboxes =/mutt-users/
mailboxes =/EstagioDocencia1
mailboxes =/mestrado/EAT
mailboxes =/P4P/

# configure it to the account where you are using mutt
set hostname="account-server-11"

set mail_check="120"
#set imap_passive="no"
set imap_keepalive="120"

set crypt_verify_sig="yes"
set pgp_sign_as="0x41D8CB10"
set crypt_autosign="yes"
set pgp_timeout="1800"

#macro index , "<change-folder>?<tab>"
#bind pager , exit
macro pager , "<sync-mailbox><change-folder>?<toggle-mailboxes>"
macro index , "<sync-mailbox><change-folder>?<toggle-mailboxes>"

macro index \ch "<save-message>imap://account-server-04/INBOX/istoe/ham<enter>" "Move a mensagem para a caixa de HAM"
macro pager \ch "<save-message>imap://account-server-04/INBOX/istoe/ham<enter>" "Move a mensagem para a caixa de HAM"
macro index \cs "<save-message>imap://account-server-04/INBOX/istoe/spam<enter>" "Move a mensagem para a caixa de SPAM"
macro pager \cs "<save-message>imap://account-server-04/INBOX/istoe/spam<enter>" "Move a mensagem para a caixa de SPAM"

.mutt/muttrc

# vide http://www.devshed.com/Server_Side/Administration/Mutt/print
# vide http://www.rohrbach.de/files/rc/.muttrc


###----------------------------------------------------------------------------
### Global Settings
###----------------------------------------------------------------------------

set quit="ask-yes"

set locale="pt_BR"
set header="yes"
set mbox_type="Maildir"
set check_new="yes"

set use_from="yes"

set imap_force_ssl="no"
set imap_servernoise="no"
set imap_list_subscribed="yes"
#set imap_passive="no"

set  nopgp_verify_sig  # should I care every time?  naah.

set spoolfile="~/Maildir/"
set folder="~/Maildir/"
set mbox="=/INBOX/"
set record="=/OUTBOX/"
#set postpone....

alternates (my_login|my_login_extended|my_nick)([-+.a-zA-Z0-9]*)?@(account-server-01|account-server-02|account-server-03|account-server-04|account-server-05|account-server-06)

set editor="/usr/bin/gvim -geometry 80x30 -f -c 'set tw=72 et ft=mail fo=tr'"
set mime_forward="ask-yes"
set header="yes"

#set hostname=account-server-06 

#set maildir_trash="yes"

set pager_context=4
set pager_index_lines=10
set pager_stop

set sig_dashes='no'
set signature='~/.mutt/signature'


###----------------------------------------------------------------------------
### Aliases
###----------------------------------------------------------------------------

set alias_file="~/.mutt/aliases"
source "~/.mutt/aliases"


###----------------------------------------------------------------------------
### Macros
###----------------------------------------------------------------------------

macro  generic	 \em  ":source ~/.muttrc\n" "Reload mutt's configuration file"



###----------------------------------------------------------------------------
### Load external global settings
###----------------------------------------------------------------------------

source ~/.mutt/accounts_account_hooks
source ~/.mutt/accounts_folder_hooks
source ~/.mutt/lists_hooks
source ~/.mutt/mailboxes-imap
source ~/.mutt/header_config
source ~/.mutt/keybind
source ~/.mutt/color


.mutt/accounts_account_hooks

###----------------------------------------------------------------------------
### Account Settings :: Account Hooks
###----------------------------------------------------------------------------

# Allways reset account-hook to sensible defaults
account-hook . '\
    unset imap_user;\
    unset imap_pass;\
    unset tunnel;'
#   set status_format="-=- DEFAULT -=- ";\

account-hook imaps://mail.account-server-01.org 'set \
    imap_user="my_login@account-server-01.org"\
    imap_pass="my_pass_at_account-server-01.org"'
    
account-hook account-server-02 'set \
    tunnel="ssh -q -C -l my_login account-server-02 /usr/bin/imapd 2>/dev/null Maildir/"'

account-hook imap://account-server-03 'set \
    tunnel="ssh -q -C -l my_login account-server-03 /home/externo/my_login/imapd 2>/dev/null Maildir/"'

account-hook imap://account-server-04 'set \
    tunnel="ssh -q -C -l my_login account-server-04 /usr/bin/imapd 2>/dev/null Maildir/"'

account-hook imap://account-server-06 'set \
    tunnel="ssh -p16123 -q -C -l my_login account-server-06 /usr/local/courier-imap/bin/imapd 2>/dev/null Maildir/"'


# Account no. 5
account-hook imaps://account-server-05 ' set \
    imap_user="my_login"'
# SSH forwarded account no. 5, since it is closed to outside access
account-hook imaps://localhost:15143 ' set \
    preconnect="ssh -f -q -L 15143:imap.account-server-05:993 -L 15145:smtp.account-server-05:25 login.account-server-05 sleep 25"\
    imap_user="my_login"'

    


.mutt/accounts_folder_hooks

###----------------------------------------------------------------------------
### Account settings :: Folder Hooks
###----------------------------------------------------------------------------


folder-hook .	'unset from;\
    set sendmail="/usr/sbin/sendmail -oem -oi";'
#    set from="my_login@account-server-09.com.br";\    

folder-hook mail.account-server-01.org/.* 'set \
    from="my_login@account-server-01.org"\
    sendmail="/usr/bin/ssh my_login@mail.account-server-01.org /usr/sbin/sendmail -oem -oi"'

folder-hook account-server-06/.* 'set \
    from="my_login@account-server-06"\
    sendmail="/usr/bin/ssh -p16123 my_login@account-server-06 /usr/sbin/sendmail -oem -oi"'
    
folder-hook account-server-02/.* 'set \
    from="my_login@account-server-02"\
    sendmail="/usr/bin/ssh my_login@account-server-02 /usr/sbin/sendmail -oem -oi"'
    
folder-hook account-server-03/.* 'set \
    from="my_login@account-server-03"\
    sendmail="/usr/bin/ssh my_login@account-server-03 /usr/sbin/sendmail -oem -oi"'
    

#Account no. 5
folder-hook localhost:15143/.* 'set \
    from="my_login@account-server-05"\
    sendmail="/usr/local/bin/esmtp -v -X /tmp/esmtp.log -f my_login@account-server-05"'
folder-hook account-server-05/.* 'set \
    from="my_login@daccount-server-05"\
    sendmail="/usr/local/bin/esmtp -v -X /tmp/esmtp.log -f my_login@account-server-05"'

# Account-server-04
folder-hook account-server-04/.* 'set \
    from="my_login@account-server-04"\
    sendmail="/usr/bin/ssh my_login@account-server-04 /usr/sbin/sendmail -oem -oi"'

.mutt/aliases

alias alu-l alu-l <alu-l@account-server-02>


.mutt/color

###----------------------------------------------------------------------------
### color config
###----------------------------------------------------------------------------

mono  message    bold
color message    white          red
color error      brightyellow   red
color indicator  black          cyan
color tree       brightmagenta  default
color signature  red            default
color attachment brightyellow   red
color search     brightyellow   red
color tilde      brightmagenta  default
color markers    brightmagenta  default
#color bold       brightblack    default
#color underline  green          default
color quoted     blue           default
color quoted1    magenta        default
color quoted2    red            default
color quoted3    green          default
color quoted4    cyan           default
color quoted5    blue           default
color quoted6    magenta        default
color quoted7    red            default
color quoted8    green          default
color quoted9    cyan           default
color hdrdefault brightred      default
color header     brightmagenta  default  "^(from):"
color header     brightblue     default  "^(subject):"
#color header     default        default  "[ \t]+[^:]*$"
color body       brightcyan     default  \
  "((ftp|http|https)://|(file|mailto|news):|www\\.)[-a-z@0-9_.:]*[a-z0-9](/[^][{} \t\n\r\"<>()]*[^][{} \t\n\r\"<>().,:])?"
color body       brightcyan     default  "[-a-z_0-9.+]+@[-a-z_0-9.]+"
color body       red            default  "(^| )\\*[-a-z0-9äöüß*]+\\*[,.?]?[ \n]"
#
# End
#

# Change the color of taged, deleted and new messages in the index

color index      white      red      ~F         # Flagged
color index      magenta    default  ~T         # Tagged
color index      cyan       default  ~N         # New
#color index     cyan       default  ~O         # Old
color index      yellow     default  ~D         # Deleted

.mutt/header_config

###----------------------------------------------------------------------------
### header config
###----------------------------------------------------------------------------

ignore User-Agent X-UIDL X-Keywords X-UID List- X-BeenThere
ignore X-Mailman-Version X-eGroups X-Yahoo-
ignore List- X-MDRemoteIP
ignore X-MIMETrack
ignore x-accept-language x-authentication-warning
ignore x-qmail
ignore X-MESINK
ignore X-Apparently-To Mailing-List X-MIME-Autoconverted Importance

unignore date

hdr_order	Return-Path: From: Resent-By: Reply-To: X-Organisation: \
		X-Address: To: Cc: Bcc: Date: Subject:

my_hdr X-PGP-Key: http://www.burocrata.org/pubkey.asc

.mutt/keybind

###----------------------------------------------------------------------------
### Binding
###----------------------------------------------------------------------------


bind pager $ imap-fetch-mail

bind index <Left>  previous-unread
bind index <Right> next-unread
bind index <Up>   previous-entry
bind index <Down>  next-entry

bind pager <Left>  previous-entry
bind pager <Right> next-entry
bind pager <Up>   previous-line
bind pager <Down>  next-line

bind  pager <backspace> previous-page
bind  pager -           previous-line
bind  pager \eOm        previous-line
bind  pager +           next-line
bind  pager \eOk        next-line
bind  pager \eOM        next-line
bind  pager \e[1~       top
bind  pager \e[4~       bottom

bind  index <backspace> previous-entry
bind  index -           previous-entry
bind  index \eOm        previous-entry
bind  index +           next-entry
bind  index \eOk        next-entry
bind  index \eOM        display-message
bind  index \e[H        first-entry
bind  index \e[F        last-entry
bind  index \e[1~       first-entry
bind  index \e[4~       last-entry

bind  alias   <space>   select-entry
bind  alias   x         exit
bind  attach  x         exit
bind  browser x         exit

.mutt/lists_hooks

send-hook . 'unmy_hdr From:'
send-hook '~t ^alu-l@account-server-02' 'my_hdr From: Tiago Macambira <my_login-alu@account-server-02>'
send-hook '~t ufcsite-l@account-server-02' 'my_hdr From: Tiago Macambira <my_login-ufcsite@account-server-02>'
send-hook '~t postfix-users@no.spam.cloud9.net' 'my_hdr From: Tiago Macambira <my_login-postfix@account-server-02>'
send-hook '~t p2p-hackers@no.spam.zgp.org' 'my_hdr From: Tiago Macambira <my_login-p2phackers@account-server-02>'
send-hook '~t decentralization@no.spam.egroups.com' 'my_hdr From: Tiago Macambira <my_login-decentralization@no.spam.account-server-02>'
send-hook '~t peleja@no.spam.yahoogrupos.com.br' 'my_hdr From: Tiago Macambira <my_login-peleja@account-server-02>'
send-hook '~t linphone-users@no.spam.nongnu.org' 'my_hdr From: Tiago Macambira <my_login-linphone@account-server-02>'

.mutt/mailboxes-imap

###----------------------------------------------------------------------------
### Global Mailboxes
###----------------------------------------------------------------------------


#mailboxes imap://account-server-03/INBOX
#mailboxes imap://account-server-03/INBOX/lia-l
#mailboxes imap://account-server-03/INBOX/formatura
#mailboxes imap://account-server-03/INBOX/gabber
#mailboxes imap://account-server-03/INBOX/mobis
#mailboxes imap://account-server-03/INBOX/caughtspam
#
##mailboxes imaps://mail.account-server-01.org/INBOX
#
#mailboxes imap://account-server-02/INBOX
#mailboxes imap://account-server-02/INBOX/alu-l
#mailboxes imap://account-server-02/INBOX/peleja
#mailboxes imap://account-server-02/INBOX/teste
#mailboxes imap://account-server-02/INBOX/ufcsite-l
#mailboxes imap://account-server-02/INBOX/pywebsvcs
#mailboxes imap://account-server-02/INBOX/linphone
#mailboxes imap://account-server-02/INBOX/postfix
#mailboxes imap://account-server-02/INBOX/faculdade/2002-2/algpara-l
#mailboxes imap://account-server-02/INBOX/faculdade/2002-2/sd-l
#mailboxes imap://account-server-02/INBOX/faculdade/2002-2/apsoo-l
#mailboxes imap://account-server-02/INBOX/faculdade/2002-2/sid-l
#mailboxes imap://account-server-02/INBOX/faculdade/2002-2/infosoc-l
#mailboxes imap://account-server-02/INBOX/deutsch-l
#mailboxes imap://account-server-02/INBOX/decentralization
#mailboxes imap://account-server-02/INBOX/p2p-hackers

mailboxes imap://account-server-04/INBOX
mailboxes imap://account-server-04/INBOX/lia
mailboxes imap://account-server-04/INBOX/caughtspam
mailboxes imap://account-server-04/INBOX/fortalnet
mailboxes imap://account-server-04/INBOX/istoe/spam
mailboxes imap://account-server-04/INBOX/istoe/ham
mailboxes imap://account-server-04/INBOX/mutt-users

#mailboxes imap://account-server-06/INBOX

# Account no. 5
mailboxes imaps://account-server-05/INBOX
#mailboxes imap://localhost:15143/INBOX
mailboxes imaps://localhost:15143/INBOX
mailboxes imaps://localhost:15143/mail/spam
mailboxes imaps://localhost:15143/mail/Sent
mailboxes imaps://localhost:15143/mail/sent-mail
mailboxes imaps://localhost:15143/mail/Trash
mailboxes imaps://localhost:15143/mail/p4p
mailboxes imaps://localhost:15143/mail/C9net
mailboxes imaps://localhost:15143/mail/planetlab
mailboxes imaps://localhost:15143/mail/carnaval
mailboxes imaps://localhost:15143/mail/inbox_antigo
mailboxes imaps://localhost:15143/mail/saved-messages
mailboxes imaps://localhost:15143/mail/projlinux
mailboxes imaps://localhost:15143/mail/exalunosgd
mailboxes imaps://localhost:15143/mail/mestrado/EAT


.mutt/mutt.xpm

/* XPM */
static char * mutt_xpm[] = {
"35 35 15 1",
" 	c None",
".	c #000000",
"+	c #BF0000",
"@	c #00BF00",
"#	c #BFBF00",
"$	c #0000BF",
"%	c #BF00BF",
"&	c #00BFBF",
"*	c #C0C0C0",
"=	c #808080",
"-	c #FF0000",
";	c #00FF00",
">	c #FFFF00",
",	c #0000FF",
"'	c #FF00FF",
"                                   ",
"                                   ",
"                                   ",
"                         ..=       ",
"                       ..          ",
"                      .**==        ",
"                     .*#*.         ",
"          .          .*#*.  ...    ",
"         .          =.*#*. .==     ",
"       =.           .=*=*...*=     ",
"       .*=         =.*******.      ",
"       .*.         .=****.*.       ",
"       .*.        =.*****.*.       ",
"       .*.=       .=********....=  ",
"       .*=.      =.*********.  %.  ",
"       .**.......-==********.*'%.  ",
"       ==*=.+++.=+-==*******.%%..  ",
"        .**=...=*=+-===******...=  ",
"        .*********=+-.===****.=.   ",
"       ===*********=+-..==***.*.   ",
"       .==**********=++..==*=.=.   ",
"       .==***********=++..... .    ",
"       .==************=.           ",
"       .==****=*=****=.            ",
"       =.=**=.===***=..            ",
"        .**=.===.**=.=.            ",
"       ==*=......=*.==.            ",
"      =.**.===. .=*.=*.            ",
"      .=**...=...=**..==.=         ",
"      .=*****.==.=*****.=*=        ",
"   = =.=*****.==.=*****.=*.        ",
"  = = .==*=**.==.==*=**.=*.        ",
"   = ==......=..=......=..=        ",
"                                   ",
"                                   "};


.mutt/signature

---
Your sig.