Super Spread Sheet S³

Or little computing tricks and hacks

Multiple mailboxes with mutt

The previous blog entry explained in detail how to install and set up mutt to retrieve and send mail using a server such as gmail. Here I’ll explain how to manage several mailbox using the same set up.

For explanations on the configuration files check the previous post.

To fetch from several mailboxes, the file .fetchmailrc needs extra information. For all the common information to all servers, start the file with the key word defaults and then include specific information under each poll:

proto POP3
mda "/usr/bin/procmail -d %T"
no keep
sslcertpath /etc/ssl/certs

# First gmail account, the official
user ""
there with password "password1"
is "user1" here

user ""
there with password "password2"
is "user2" here

All of the servers will use POP3 and the same SSL certificates. The MDA is procmail. Notice that any server can be used. I just haven't tested any other so I don't have the server URL. Fetchmail man pages suggest to stash the account/password pairs in your $HOME/.netrc file where this information can be used for FTP and other programs. Check that this is working by typing

  fetchmail -v

If you have different mailboxes, they are probably of a different type, so you want to sort them in different inboxes. Procmail will do this through the recipes in the .procmailrc file:

# Environment variable assignments
VERBOSE=off                   # Turn on for verbose log
MAILDIR=$HOME/Mail            # Where procmail delivers recipes
LOGFILE=$HOME/.procmaillog    # Keep a log for troubleshooting.

# Recipes
* ^To.*user1|^From.*user1|

* ^To.*user2|^From.*user2|

In the first recipe all mail sent to or received from, actually all mail which includes the full email in the header is to be directed to mailbox1. Similarly for for the next recipe. This will make sure that even the Cc are included.

Now mutt needs to know about the different mailboxes and about the different accounts available to send mail. The file .muttrc needs to include the following:

  mailboxes ! +mailbox1 +mailbox2

After running fetchmail, procmail has done the sorting and running

  mutt -y

will show the list of all the mailboxes with N next to the ones with new mail. I included the following line in the configuration file for a cleaner view of the listing:

  set folder_format="%2C %t %N %8s %d %f"

To be able to send mail from these different mailboxes, both mutt and msmtp have to have the right configurations files. For mutt, the easiest thing is to have as many .muttrc files as email address you want to send mail from, changing the appropriate details for setting msmtp in mutt, namely:

set realname = "John The Big Brother"
set from =

and name each of them differently, say .muttrc_mb1 and .muttrc_mb2. Then create an aliases, in .bashrc like so (taken from this link):

alias mb1='mutt -F /home/you/.muttrc_mb1'
alias mb2='mutt -F /home/you/.muttrc_mb2'

which meant that you have to know which email address you want to send email from before calling mutt. What I do is to have a default and the others are for specific occasions.

You can also try muttprofile, but I have not bothered to try it as the current set up does not bother me.

The .msmtprc describes each email account under the keyword account. At the beginning of the file under defaults, you can set the global values for all the accounts. The define each account in turn, with the option of later ones inheriting from earlier ones.

# Set default values for all following accounts
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
auth on

# First account
account main
port 587            
from ""                 
user "john.example"       
password "rover"

# Second account
account other : main
port 587            
from ""                 
user "john.other"       
password "rover2"

# Set a default account
account default : main

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s