mutt with multiple accounts

glorious mutt

I’ve been using Neomutt for about 2 months now trying out different setups, tweaking the config here and there. Here’s what I’ve found works best if you would like Neomutt to handle all of your IMAP and SMTP functionality. If you plan on using this as a guide I recommend doing so while cross referencing the manpage.

So heres my dir layout. /{cache,headers,messages} should be created to store cacheable data to drastically improve startup time and decrease lag moving through Neomutt - .muttrc is symlinked to ~/.muttrc.

~/.mutt ❯  ls
cache/         secrets/       imap.account2          sidebar
certificates/  temp/          .muttrc                sig
headers/       binds          mailcap      *
messages/      imap.account1  mutt_bgrun


source ~/.config/neomutt/binds
source ~/.mutt/imap.account1

set my_gpass1   = `gpg -q -d ~/.my_pass.gpg`
set my_gpass2   = `gpg -q -d ~/.my_pass2.gpg`
account-hook imap.account1 'set
imap_pass=`gpg -q -d ~/.my_pass.gpg`'
account-hook imap.account2 'set

# pgp
set crypt_replyencrypt
set crypt_replysign
set crypt_replysignencrypted
set pgp_show_unusable           ="no"

# general globals
set fast_reply
alternative_order               = "text/plain text/enriched text/html"
auto_view                       = "text/html"
# New mail notification
set new_mail_command            ="~/bin/ &"
set resolve                     = "no"

The only thing I have i keep in here are global settings, the required login credentials, and the default account I would like Neomutt to present on opening. The account-hooks tell Neomutt to use those particular credentials when switching accounts.

Account Config Files

Here’s the “main” configuration. Exercise whatever repressed artistic expression you want when naming these, its not important.

# Sources
source "~/.mutt/muttrc.sidebar.canibaoxa"
source "~/.mutt/muttrc.monstar_island"
source "~/.mutt/binds

# paths
set message_cachedir    = "~/.mutt/messages"
set certificate_file    = "~/.mutt/certificates"
set mailcap_path        = "~/.mutt/mailcap"
set tmpdir              = "~/.mutt/temp"
set signature           = "~/.mutt/account1.sig"

monstar_island is my (incomplete) color file. You source those just like everything else.

The mailcap file tells Neomutt (and many other applications) how to handle certain individual MIME types. That’s a guide all it’s own so I’ll point you to the Neomutt documentation for that.

# user
set realname            = "Viktor Vaughn"
set imap_user           = ""
set imap_pass           = `gpg -q -d  ~/.mutt/secrets/password.gpg`
set smtp_url            = "smtp://"
set smtp_pass           = `gpg -q -d  ~/.mutt/secrets/password.gpg`
set folder              = "imaps://"
set spoolfile           = imaps://
set imap_check_subscribed

set pgp_sign_as         = 0xabcd1234
set pgp_autosign

set ssl_starttls        = yes
set ssl_force_tls       = yes

set from                = ""
set use_from            = "yes"
set envelope_from
set postponed           = "+[Gmail]/Drafts"
set trash               = "+[Gmail]/Trash"
unset record
set query_command       = "goobook query '%s'"
set text_flowed         = yes
set editor              = "vim -c 'set spell spelllang=en'"
set sig_dashes
set fcc_attach
set reply_to
set reverse_name
set include
set edit_headers
set autoedit            # take me right to vim editor
set forward_quote
unset mime_forward
# inbox
set mbox_type           = Maildir
set timeout             = 60
set mail_check          = 60
set imap_keepalive      = 30
unset imap_passive
set delete
set quit
set pipe_decode
set thorough_search
unset confirmappend
unset mark_old

# headers
ignore *
unignore  X-Bogosity From: To: Cc: Date:
hdr_order X-Bogosity From: To: Cc: Date:
#unignore From: Subject: To: Cc:

set forward_format      = "Fwd: %s"
set date_format = "%m/%d•%H:%M"
set index_format = "%Z ⌈%D⌋ %-20.20F ⌜%s⌟"
set implicit_autoview
alternative_order text/plain text/html text/encriched
auto_view text/html
set sort                = "reverse-threads"
set sort_browser        = "alpha"
set sort_aux            = "last-date-received"
set uncollapse_jump
set sort_re
set reply_regexp = "^(([Rr][Ee]?(\[[0-9]+\])?: *)?(\[[^]]+\] *)?)*"

# macros
macro index,pager A **"<save-message>=[Gmail]/All%20Mail<enter><enter>" "Archive
macro index,pager gi "=INBOX" "Go to inbox"
macro index,pager ga "=All Mail" "Go to all mail"
macro index,pager gs "=Sent Mail" "Go to starred messages"
macro index,pager gd "=Drafts" "Go to drafts"

Note the %20 to escape the spaces in your IMAP folder names.

Once you have each account configured the only thing left to do is to tell Neomutt how to switch accounts. That’s done through a simple macro that I keep in ~/.mutt/binds.

macro index <f4> '<sync-mailbox><enter-command>\
    source ~/.mutt/imap.account1\
macro index <f5> '<sync-mailbox><enter-command>\
    source ~/.mutt/imap.acount2\

That it. Hopefully this wasn’t too sparse for you to get Neomutt functioning with multiple accounts. If you have any questions or concerns feel free to contact me I’ll be happy to respond. You can also check my github for a more up-to-date and complete example of how to get this working.