Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple accounts with Mutt E-Mail Client (gmail example)

How to set up multiple accounts with Mutt E-mail Client

Thanks to this article by Christoph Berg

Instructions

Directories and files

~/
|── .mutt/
|   ├── account.com.gmail.foo
|   ├── account.com.gmail.bar
|   ├── com.gmail.foo/
|   └── com.gmail.bar/
└── .muttrc
~/.muttrc
# Folder hooks
folder-hook 'account.com.gmail.foo' 'source ~/.mutt/account.com.gmail.foo'
folder-hook 'account.com.gmail.bar' 'source ~/.mutt/account.com.gmail.bar'

# Default account
source ~/.mutt/account.com.gmail.foo         

# Macros for switching accounts
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/account.com.gmail.foo<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/account.com.gmail.bar<enter><change-folder>!<enter>'

# Fetch mail shortcut
bind index G imap-fetch-mail
~/.mutt/account.com.gmail.foo
set imap_user = "foo@gmail.com"                       
set imap_pass = "<PASSWORD>"                                    
set smtp_url = "smtp://foo@smtp.gmail.com:587/"       
set smtp_pass = "<PASSWORD>"                                    
set from = "foo@gmail.com"                            
set realname = "Foo"                                  
set folder = "imaps://imap.gmail.com:993"                     
set spoolfile = "+INBOX"                                      
set postponed = "+[Gmail]/Drafts"                             
set header_cache = ~/.mutt/com.gmail.foo/cache/headers            
set message_cachedir = ~/.mutt/com.gmail.foo/cache/bodies         
set certificate_file = ~/.mutt/com.gmail.foo/certificates         
~/.mutt/account.com.gmail.bar
set imap_user = "bar@gmail.com"                       
set imap_pass = "<PASSWORD>"                                    
set smtp_url = "smtp://bar@smtp.gmail.com:587/"       
set smtp_pass = "<PASSWORD>"                                    
set from = "bar@gmail.com"                            
set realname = "Bar"                                  
set folder = "imaps://imap.gmail.com:993"                     
set spoolfile = "+INBOX"                                      
set postponed = "+[Gmail]/Drafts"                             
set header_cache = ~/.mutt/com.gmail.bar/cache/headers            
set message_cachedir = ~/.mutt/com.gmail.bar/cache/bodies         
set certificate_file = ~/.mutt/com.gmail.bar/certificates         
@passionaqua

This comment has been minimized.

Show comment
Hide comment
@passionaqua

passionaqua Jun 25, 2014

Thanks! Really helpful! 👍

passionaqua commented Jun 25, 2014

Thanks! Really helpful! 👍

@gotbletu

This comment has been minimized.

Show comment
Hide comment
@gotbletu

gotbletu Jan 31, 2015

Thanks this was useful but i was confused by the structure

Think you meant
account = text files
com = folders

~/
|── .mutt/
|   ├── account.com.gmail.foo
|   ├── account.com.gmail.bar
|   ├── com.gmail.foo/
|   └── com.gmail.bar/
└── .muttrc

gotbletu commented Jan 31, 2015

Thanks this was useful but i was confused by the structure

Think you meant
account = text files
com = folders

~/
|── .mutt/
|   ├── account.com.gmail.foo
|   ├── account.com.gmail.bar
|   ├── com.gmail.foo/
|   └── com.gmail.bar/
└── .muttrc
@blacksails

This comment has been minimized.

Show comment
Hide comment
@blacksails

blacksails Apr 11, 2015

Isen't it redundant having folder hooks doing the same thing as the macros?
I don't think you should source the files in the macros, isen't that what the folder hooks are for?

blacksails commented Apr 11, 2015

Isen't it redundant having folder hooks doing the same thing as the macros?
I don't think you should source the files in the macros, isen't that what the folder hooks are for?

@srikawnth

This comment has been minimized.

Show comment
Hide comment
@srikawnth

srikawnth Apr 27, 2015

Hi, I am using mutt sidebar patch. When i switch account, I could still see old account labels inside this account. How could i refresh the sidebar with the active account labels?

srikawnth commented Apr 27, 2015

Hi, I am using mutt sidebar patch. When i switch account, I could still see old account labels inside this account. How could i refresh the sidebar with the active account labels?

@zergler

This comment has been minimized.

Show comment
Hide comment
@zergler

zergler Jun 28, 2015

To refresh the sidebar, you have to put this in all of your account files and change the mailboxes command to include all the mailboxes you want to show up. But I think there is a bug in the unmailboxes * command which I'm not sure has been fixed yet.

unmailboxes *
mailboxes "+Inbox" "+[Gmail]/All Mail"

zergler commented Jun 28, 2015

To refresh the sidebar, you have to put this in all of your account files and change the mailboxes command to include all the mailboxes you want to show up. But I think there is a bug in the unmailboxes * command which I'm not sure has been fixed yet.

unmailboxes *
mailboxes "+Inbox" "+[Gmail]/All Mail"

@bruno-

This comment has been minimized.

Show comment
Hide comment
@bruno-

bruno- Aug 14, 2015

@zergler thanks for the unmailboxes * tip. That should be the solution, but unfortunately there's a bug and it doesn't really work. If I invoke that command manually I get a segmentation fault with mutt :(

bruno- commented Aug 14, 2015

@zergler thanks for the unmailboxes * tip. That should be the solution, but unfortunately there's a bug and it doesn't really work. If I invoke that command manually I get a segmentation fault with mutt :(

@shioyama

This comment has been minimized.

Show comment
Hide comment
@shioyama

shioyama Dec 7, 2015

If anybody is struggling with this segfault issue, it's a known issue with the sidebar and the unmailboxes command but I've found that it can be fixed by using refresh before unmailboxes.

I have some source files for each mailbox which start with unmailboxes * to clear the sidebar. My macros look like this:

# Macros for switching accounts
macro index <f2> '<sync-mailbox><refresh><enter-command>source ~/.mutt/gmail<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><refresh><enter-command>source ~/.mutt/fastmail<enter><change-folder>!<enter>'
...

You see that I added the <refresh> just before sourcing the files with unmailboxes. This has the added benefit of updating sidebar numbers so that they are correct for all mailboxes when you switch, and I find now that I don't get any more segfaults or issues. But, YMMV.

shioyama commented Dec 7, 2015

If anybody is struggling with this segfault issue, it's a known issue with the sidebar and the unmailboxes command but I've found that it can be fixed by using refresh before unmailboxes.

I have some source files for each mailbox which start with unmailboxes * to clear the sidebar. My macros look like this:

# Macros for switching accounts
macro index <f2> '<sync-mailbox><refresh><enter-command>source ~/.mutt/gmail<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><refresh><enter-command>source ~/.mutt/fastmail<enter><change-folder>!<enter>'
...

You see that I added the <refresh> just before sourcing the files with unmailboxes. This has the added benefit of updating sidebar numbers so that they are correct for all mailboxes when you switch, and I find now that I don't get any more segfaults or issues. But, YMMV.

@cambrant

This comment has been minimized.

Show comment
Hide comment
@cambrant

cambrant Jan 13, 2016

@shioyama That sounded exactly like it would solve my problem, where unmailboxes * before setting mailboxes again would result in me having only +Inbox in my sidebar after switching accounts, but instead I just get a couple of weird characters in the sidebar. Are you running 1.5.24?

I'll have a look at the patch next and try to fix the issue, but I'm sure it's a bit more complicated than it seems now.

cambrant commented Jan 13, 2016

@shioyama That sounded exactly like it would solve my problem, where unmailboxes * before setting mailboxes again would result in me having only +Inbox in my sidebar after switching accounts, but instead I just get a couple of weird characters in the sidebar. Are you running 1.5.24?

I'll have a look at the patch next and try to fix the issue, but I'm sure it's a bit more complicated than it seems now.

@cambrant

This comment has been minimized.

Show comment
Hide comment
@cambrant

cambrant Jan 30, 2016

Everything seems to be working fine for me when I use mutt-lightweight-sidebar. Not sure if all functionality is there, but I can unmailboxes * just fine.

cambrant commented Jan 30, 2016

Everything seems to be working fine for me when I use mutt-lightweight-sidebar. Not sure if all functionality is there, but I can unmailboxes * just fine.

@Leandros

This comment has been minimized.

Show comment
Hide comment
@Leandros

Leandros Jan 31, 2016

What version are you using @cambrant ?
I've switched to that patch, and I've got the same issues as with the old patch, my sidebar looks totally scrambled after switching.

Leandros commented Jan 31, 2016

What version are you using @cambrant ?
I've switched to that patch, and I've got the same issues as with the old patch, my sidebar looks totally scrambled after switching.

@andreas-bulling

This comment has been minimized.

Show comment
Hide comment
@andreas-bulling

andreas-bulling Apr 19, 2016

same issue here - I also only get scrambled characters in the sidebar after switching accounts (I am running 1.6.0)

Any update on this? Does anybody know a fix?

andreas-bulling commented Apr 19, 2016

same issue here - I also only get scrambled characters in the sidebar after switching accounts (I am running 1.6.0)

Any update on this? Does anybody know a fix?

@oblitum

This comment has been minimized.

Show comment
Hide comment
@oblitum

oblitum Sep 26, 2016

Instead of getting stuck with bugs as everyone is talking about I've instead opted to just load multiple accounts in specific tmux windows. I'm using tmuxp to load them all easily, with just a command (tmuxp load mail) I load all my accounts in a new "mail" tmux session, with each account in its own tmux window running its own mutt instance.

oblitum commented Sep 26, 2016

Instead of getting stuck with bugs as everyone is talking about I've instead opted to just load multiple accounts in specific tmux windows. I'm using tmuxp to load them all easily, with just a command (tmuxp load mail) I load all my accounts in a new "mail" tmux session, with each account in its own tmux window running its own mutt instance.

@stormdragon2976

This comment has been minimized.

Show comment
Hide comment
@stormdragon2976

stormdragon2976 Apr 23, 2017

I wonder if anyone here would be interested in helping with https://github.com/2mb-solutions/fleacollar? My idea is to make email configuration with mutt really simple. It handles practically everything from gpg to multiple email address. It's even pretty close to working. It sure would be nice having someone who has a better grasp of folder hooks and things to help out though.

stormdragon2976 commented Apr 23, 2017

I wonder if anyone here would be interested in helping with https://github.com/2mb-solutions/fleacollar? My idea is to make email configuration with mutt really simple. It handles practically everything from gpg to multiple email address. It's even pretty close to working. It sure would be nice having someone who has a better grasp of folder hooks and things to help out though.

@b0o

This comment has been minimized.

Show comment
Hide comment
@b0o

b0o Nov 23, 2017

Thanks for this!
I wanted to configure mutt so that I can commit my main configuration files publicly, while my account-specific configurations remain private. Here's what I've done:

~/.muttrc:

# Folder hooks
folder-hook "$MUTT_ACCOUNT_1" 'source ~/.mutt/$MUTT_ACCOUNT_1'
folder-hook "$MUTT_ACCOUNT_2" 'source ~/.mutt/$MUTT_ACCOUNT_2'

# Default account
source ~/.mutt/$MUTT_ACCOUNT_1

# Macros for switching accounts
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/$MUTT_ACCOUNT_1<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/$MUTT_ACCOUNT_2<enter><change-folder>!<enter>'

# Fetch mail shortcut
bind index G imap-fetch-mail

~/.private/mutt

#!/bin/bash
export MUTT_ACCOUNT_1="account.com.gmail.foo"
export MUTT_ACCOUNT_2="account.com.gmail.bar"

~/bin/mutt

#!/bin/bash
source $DOTFILES/private/mutt
/usr/bin/mutt

~/.zshrc

alias mutt $HOME/bin/mutt

Now I can keep my .muttrc in my dotfiles repo without worrying about my email addresses or passwords leaking, as long as I keep my ~/.mutt and ~/.private directories private.

b0o commented Nov 23, 2017

Thanks for this!
I wanted to configure mutt so that I can commit my main configuration files publicly, while my account-specific configurations remain private. Here's what I've done:

~/.muttrc:

# Folder hooks
folder-hook "$MUTT_ACCOUNT_1" 'source ~/.mutt/$MUTT_ACCOUNT_1'
folder-hook "$MUTT_ACCOUNT_2" 'source ~/.mutt/$MUTT_ACCOUNT_2'

# Default account
source ~/.mutt/$MUTT_ACCOUNT_1

# Macros for switching accounts
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/$MUTT_ACCOUNT_1<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/$MUTT_ACCOUNT_2<enter><change-folder>!<enter>'

# Fetch mail shortcut
bind index G imap-fetch-mail

~/.private/mutt

#!/bin/bash
export MUTT_ACCOUNT_1="account.com.gmail.foo"
export MUTT_ACCOUNT_2="account.com.gmail.bar"

~/bin/mutt

#!/bin/bash
source $DOTFILES/private/mutt
/usr/bin/mutt

~/.zshrc

alias mutt $HOME/bin/mutt

Now I can keep my .muttrc in my dotfiles repo without worrying about my email addresses or passwords leaking, as long as I keep my ~/.mutt and ~/.private directories private.

@1094

This comment has been minimized.

Show comment
Hide comment
@1094

1094 Feb 13, 2018

Hi. I was wondering if you'd be able to help. I am using the sidebar in mutt and have marcos set up to switch accounts. What I would like to do is remove the sidebar and have all emails from all accounts showing in the default index. Do you know how I would do that? I tried to google it, but everything leads to a set-up much like this.

1094 commented Feb 13, 2018

Hi. I was wondering if you'd be able to help. I am using the sidebar in mutt and have marcos set up to switch accounts. What I would like to do is remove the sidebar and have all emails from all accounts showing in the default index. Do you know how I would do that? I tried to google it, but everything leads to a set-up much like this.

@TravelTrader

This comment has been minimized.

Show comment
Hide comment
@TravelTrader

TravelTrader Feb 24, 2018

I do not use gmail but I had mutt already running.
I changed my files with your script and added one more account and --- it worked immediately!

I added $my_server to not repeat this and to easier add more accounts by simply use cp ...
Thanks.

--- I will implement pwd-protection soon ---

TravelTrader commented Feb 24, 2018

I do not use gmail but I had mutt already running.
I changed my files with your script and added one more account and --- it worked immediately!

I added $my_server to not repeat this and to easier add more accounts by simply use cp ...
Thanks.

--- I will implement pwd-protection soon ---

@erji44

This comment has been minimized.

Show comment
Hide comment
@erji44

erji44 Mar 6, 2018

I have four accounts set up the way described above.
Two of the accounts are gmail and it works fine whereas the other account is on another server.
Problem I'm having is the gmail accounts work fine when the default account is set to gmail.
When I try and change to the accounts on the other server I get login failed.
Same thing a happens if I try and change the default account as one of the other two accounts, the other accounts work and when I try change to gmail I get again login failed.
Individually the accounts work fine but seems like change of server causes a problem.

Any thoughts?
Thank you

erji44 commented Mar 6, 2018

I have four accounts set up the way described above.
Two of the accounts are gmail and it works fine whereas the other account is on another server.
Problem I'm having is the gmail accounts work fine when the default account is set to gmail.
When I try and change to the accounts on the other server I get login failed.
Same thing a happens if I try and change the default account as one of the other two accounts, the other accounts work and when I try change to gmail I get again login failed.
Individually the accounts work fine but seems like change of server causes a problem.

Any thoughts?
Thank you

@tuannvm

This comment has been minimized.

Show comment
Hide comment
@tuannvm

tuannvm Jun 18, 2018

@erji44

You're right, when we change account, we do need to change folder as well. For example I have 4th account using yandex, here is the necessary config:

macro index <f4> '<sync-mailbox><enter-command>source ~/.mutt/account.com.yandex.bar<enter><change-folder>imaps://imap.yandex.com<enter>'

tuannvm commented Jun 18, 2018

@erji44

You're right, when we change account, we do need to change folder as well. For example I have 4th account using yandex, here is the necessary config:

macro index <f4> '<sync-mailbox><enter-command>source ~/.mutt/account.com.yandex.bar<enter><change-folder>imaps://imap.yandex.com<enter>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment