4

Can anybody help me with mutt configuration?

I need to configure mutt to support mutiple accounts the same time.

At this moment my config file for personal email looks like this:

~ $ cat ~/.mutt/personal

set imap_user = «%personal_email%@gmail.com»
set imap_pass = «%personal_email_pass%»
set smtp_url = «smtps://%personal_email%@smtp.gmail.com:465/»
set smtp_pass = «%personal_email_pass%»
set from = «%personal_email%»
set realname = «%username%»
set hostname = gmail.com
set folder = «imaps://%personal_email%@imap.gmail.com:993»
set spoolfile = «imaps://%personal_email%@imap.gmail.com/INBOX»
set postponed = «imaps://%personal_email%@imap.gmail.com/[Gmail]/Drafts»
set record = «imaps://%personal_email%@imap.gmail.com/[Gmail]/Sent Mail»

"~/.mutt/work" looks the same way, except the values of "%personal_email%" and "%personal_email_pass%", of course.

"~/.muttrc" looks like this:

~ $ cat ~/.muttrc

source «~/.mutt/personal»

macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/personal<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/work<enter><change-folder>!<enter>'

When I press F2 or F3 mutt really changes an account, but when I'm trying to change mailbox (via 'c' -> '?') it opens a mailbox of the first account (in my case "personal") even when the current account is "work".

Why? What am I doing wrong? How can I fix it?

1
  • You might have better luck with the mutt user mailing list. Commented Apr 8, 2014 at 15:17

2 Answers 2

3

Some trickery with hooks. You might want to think twice about storing passwords into .muttrc. At least take care to use application specific passwords instead of your main Google account password when you do something as insecure as this.

# Gmail account passwords and usernames
set my_gmail_user1 = "<account 1, without @gmail or anything>"
set my_gmail_user2 = "<account 2, without @gmail or anything>"
set my_gmail_pass1 = "<password, hopefully an app-specific one>"  
set my_gmail_pass2 = "<password, hopefully an app-specific one>"  

# Account hooks
account-hook . "unset imap_user ; unset imap_pass"
account-hook "imaps://[email protected]" "\
    set imap_user = $my_gmail_user1 \
            imap_pass = $my_gmail_pass1"
account-hook "imaps://[email protected]" "\
    set imap_user = $my_gmail_user2 \
            imap_pass = $my_gmail_pass2"

# Gmail folders
set folder          = imaps://[email protected]/
mailboxes           = +INBOX =[Gmail]/Drafts =[Gmail]/'Sent Mail' =[Gmail]/Spam =[Gmail]/Trash
set spoolfile       = +INBOX
folder-hook         imaps://[email protected]/ "\
    set folder      = imaps://[email protected]/ \
        spoolfile   = +INBOX \
        postponed   = +[Gmail]/Drafts \
        record      = +[Gmail]/'Sent Mail' \
        from        = 'First User Real Name <[email protected]> ' \
        realname    = 'First User Real Name' \
        smtp_url    = smtps://[email protected] \
        smtp_pass   = $my_gmail_pass1"
set folder          = imaps://[email protected]/
mailboxes           = +INBOX =[Gmail]/Drafts =[Gmail]/'Sent Mail' =[Gmail]/Spam =[Gmail]/Trash
set spoolfile       = +INBOX
folder-hook         imaps://[email protected]/ "\
    set folder      = imaps://[email protected]/ \
        spoolfile   = +INBOX \
        postponed   = +[Gmail]/Drafts \
        record      = +[Gmail]/'Sent Mail' \
        from        = 'First User Real Name <[email protected]> ' \
        realname    = 'First User Real Name' \
        smtp_url    = smtps://[email protected] \
        smtp_pass   = $my_gmail_pass2"

Now all there is left to it is to fire up mutt, then hit y and select the folder for an account you want.

If you want more secure setup, your favorite search engine can tell you how to secure IMAP/POP passwords for Mutt with PGP. Realname/from is left as an exercise for the reader.

2
  • I'm interested in using different accounts based on recipient. Looks like you can do this with send-hooks, but how to set things back after the mail is sent?
    – Chris W.
    Commented Apr 23, 2014 at 16:44
  • While this answer might illustrate how to setup multiple accounts with mutt the TO already accomplished this task. So this does not in any way answer the question: "Why does mutt offer to open a mailbox (by typing "c") belonging to the first account regardless of the fact that the second account is active."
    – Gen.Stack
    Commented Feb 19, 2019 at 22:55
1

I am using mutt in a similar way and also noticed that mutt does not offer to open right away a mailbox belonging to the currently active account (not being the first one) when just typing c.

You may, however, type c then = and TAB thrice and you will be shown the mailboxes of the currently active account. Hitting TAB again will even allow you to switch between your different accounts' mailboxes.

So far, AFAICT, within mutt there lies no solution (yet) to your question "Why does mutt - when typing c - offer to open a mailbox belonging to the first account, regardless of the fact that another/second account is active.".

My best guess is, it's either a deliberate design choice or a bug no one cared to fix yet. Using [neo]mutt's sidebar might also alleviate the UX.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .