Feb 27, 2009

Multiple accounts in Mutt

Q: How to set up multiple accounts in Mutt?
A: Three steps:
  1. Set up multiple accounts in fetchmail to receive emails from different accounts;
  2. set up multiple accounts in msmtp to send email with multiple accounts;
  3. set up multiple accounts control in mutt.
The first step is explained in my Mutt tutorial post. I assume now you can receive different emails from This post will focus on how to control send emails with different accounts.

First of, you need to have multiple accounts setting in your .msmtprc file. For example, here I have two Gmail accounts setting:

account gmail
host smtp.gmail.com
port 587
from goodguy@gmail.com
tls on
tls_starttls on
tls_trust_file /home/usrname/mail/certs/Thawte_Premium_Server_CA.pem
auth on
user goodguy
password 1234567

account gmail1
host smtp.gmail.com
port 587
from badguy@gmail.com
tls on
tls_starttls on
tls_trust_file /home/usrname/mail/certs/Thawte_Premium_Server_CA.pem
auth on
user badguy
password abcdefg

account default: gmail

Default account is the first account, as specified in the config file. Now what you need to do is to control when to send email with first account, and when with the second account.

You need add the following lines to your .muttrc file to enable multiple accounts support.

Few things to explain. There is a "from" environment in your .muttrc file. If the default value is goodguy@gmail.com, your default account when composing email or replying email sent to accounts other than the emails specified in "alternate" emails is goodguy@gmail.com.

The ugly status set in the macro is to help you know what the "from" environment is.

set envelope_from ="yes"

set reverse_name=yes

alternates "goodguy@gmail.com|badguy@gmail.com"

macro index \e1 ":set signature=~/.signature_private\n:\
set from=goodguy@gmail.com\n:set status_format=\"-%r-Gmail: %f \
[Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? \
Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---\"\n"\
"Switch to Gmail"

macro index \e2 ":set signature=~/.signature_fake\n:\
set from=badguy@gmail.com\n:set realname=Jason\n:set status_format=\"-%r-Gmail2: %f \
[Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? \
Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---\"\n"\
"Switch to Gmail2"

The first three lines are to enable email matching during reply. That is, when you are replying emails sent to goodguy@gmail.com, the "From:" header is automatically set as goodguy@gmail.com, so that you don't need to set which account to use manually before reply. Note that this will not change the "from" environment, so when you compose new mail, the "From:" header will be the default "from" environment in .muttrc file, or others if you have manually changed the "from" environment as shown below.

If you need to compose a new email, you can choose which account to use by pressing ALT+1 or ALT+2, which will set the "from" environment to goodguy@gmail.com and badguy@gmail.com respectively.

Once you specified your "From:" header, msmtp will compare the header with "from" line in .msmtprc file, to find account with that email address to send the email. If msmtp can't find one, it will send email with default account in .msmtprc file.

OK, Done.

1 comment:

~brigante said...

great man ;-)

i've searched a lot of time for found a tutorial like this, on mutt =>1.5.20 this is the only solution for use multiple account.

hi && thx :)

Welcome to Non-geek's
Linux Handbook!

or if you will, Linux Cookbook.

tutorials on Linux applications~

Subscribe if you are willing to follow.

If you find the post useful, please click the donate button on the upper right corner. Any amount is useful.