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. – Faheem Mitha Apr 8 '14 at 15:17
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://$my_gmail_user1@imap.gmail.com" "\
    set imap_user = $my_gmail_user1 \
            imap_pass = $my_gmail_pass1"
account-hook "imaps://$my_gmail_user2@imap.gmail.com" "\
    set imap_user = $my_gmail_user2 \
            imap_pass = $my_gmail_pass2"

# Gmail folders
set folder          = imaps://$my_gmail_user1@imap.gmail.com/
mailboxes           = +INBOX =[Gmail]/Drafts =[Gmail]/'Sent Mail' =[Gmail]/Spam =[Gmail]/Trash
set spoolfile       = +INBOX
folder-hook         imaps://$my_gmail_user1@imap.gmail.com/ "\
    set folder      = imaps://$my_gmail_user1@imap.gmail.com/ \
        spoolfile   = +INBOX \
        postponed   = +[Gmail]/Drafts \
        record      = +[Gmail]/'Sent Mail' \
        from        = 'First User Real Name <$my_gmail_user1@gmail.com> ' \
        realname    = 'First User Real Name' \
        smtp_url    = smtps://$my_gmail_user1@smtp.gmail.com \
        smtp_pass   = $my_gmail_pass1"
set folder          = imaps://$my_gmail_user2@imap.gmail.com/
mailboxes           = +INBOX =[Gmail]/Drafts =[Gmail]/'Sent Mail' =[Gmail]/Spam =[Gmail]/Trash
set spoolfile       = +INBOX
folder-hook         imaps://$my_gmail_user2@imap.gmail.com/ "\
    set folder      = imaps://$my_gmail_user2@imap.gmail.com/ \
        spoolfile   = +INBOX \
        postponed   = +[Gmail]/Drafts \
        record      = +[Gmail]/'Sent Mail' \
        from        = 'First User Real Name <$my_gmail_user2@gmail.com> ' \
        realname    = 'First User Real Name' \
        smtp_url    = smtps://$my_gmail_user2@smtp.gmail.com \
        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. Apr 23 '14 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 Feb 19 '19 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.