[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]
LINUX GAZETTE
...making Linux just a little more fun!
Multi-Account E-mail with Mutt
By Kamil Klimkiewicz

About three or four months ago I switched from Windows to Linux. I had been using Linux before but it was only my second operating system. When it became my primary one I had to deal with several problems. Most of them I was able to fix quickly. There was one thing which caused many troubles - I had three e-mail accounts.

Windows user could say, "Download some e-mail client and configure it to use several accounts." But there is something called the 'Unix philosophy'. It says that programmers should write small applications which do only one thing but do it well. What does it mean for us? It means that there is no single tool which fetches your mail from remote server, allows you to read and write mail and sends it to its target.

In this short article I will only show you how to configure tools called fetchmail and mutt. If you want to go deeper into this topic you should read:

You can get them from http://www.linuxdoc.org.

1. Environment

Let's define our e-mail environment: we have three e-mail accounts, each placed on different server. We will call them 'First', 'Second' and 'Third.' Their addresses are: first@firstdomain.com, second@seconddomain.com, third@thirddomain.com. Moreover the first account uses IMAP protocol and the others POP3.

The local user who is going to receive all the messages is called 'john'. We need to set new value for $MAIL environment variable, since we won't use default '/var/spool/mail/john' (this is unsafe and less convenient.) To do this we add following lines to .bash_profile (of course if you use different shell you have to change different things):

MAIL=$HOME/Mail/Inbox
export MAIL

(Don't forget to create directory '$HOME/Mail'!.) We will also use additional mailboxes for read messages (each account has its associated box.)

2. Fetchmail

Before we can read our mail we have to fetch it from remote server. To do this we will use a tool called fetchmail. It should be already installed on your system.

Configuring fetchmail is quite easy task. Moreover we can use utility 'fetchmailconf' which makes the process even easier. Configuration file we should edit is $HOME/.fetchmailrc. Simple one, appropriate for our environment, looks like this:

set postmaster "john"
set bouncemail
set properties ""
set daemon 300
poll First via firstdomain.com
 with proto IMAP
       user first there with password this_is_password is john here warnings 3600

poll Second via seconddomain.com
 with proto POP3
       user second there with password this_is_password is john here warnings 3600

poll Second via thirddomain.com
 with proto POP3
       user third there with password this_is_password is john here warnings 3600

To run fetchmail you only need to type fetchmail. It will be started in daemon mode and will check whether there is new mail every 5 minutes.

3. Mutt

Our messages are on local machine now, so we can read them using any Mail User Agent. I assume it is mutt because this article is intended to deal with mutt.

Mutt needs to be configured before it can work like we want. First of all we have to put some basic definitions in its configuration file (it is usually called $HOME/.muttrc.) They can look like this:

set mbox = "~/Mail/Inbox"
set move = no
set folder = "~/Mail"
set record = +Sent
mailboxes +Inbox +First +Second +Third

This actually allows us to read the messages but every outgoing message will have something like john@localhost in its From header field. We should be able to change the sender address so the message can look like it was sent from firstdomain.com or seconddomain.com or whatever machine you have account on.

To achieve this we use additional mailboxes (First, Second and Third) and mutt's so called hooks mechanism. The latter executes user defined commands when some action is being performed. There is folder-hook which is called when user changes mail folder (by pressing 'c' key.) To change the From field we need to modify from and realname mutt variables:

# Default action:
folder-hook . set from = first@firstdomain.com
folder-hook . set realname = First
# First account:
folder-hook First set from = first@firstdomain.com
folder-hook First set realname = First
# Second account:
folder-hook Second set from = second@seconddomain.com
folder-hook Second set realname = Second
# Third account:
folder-hook Third set from = third@thirddomain.com
folder-hook Third set realname = Third

We should also define the alternates variable so mutt can recognize messages sent to and by us:

set alternates = "first@firstdomain\.com|second@seconddomain\.com|third@thirddomain\.com"

Note: There is a web tool called MuttrcBuilder at http://mutt.netliberte.org which you can use to configure your mutt.


Copyright © 2002, Kamil Klimkiewicz. Copying license http://www.linuxgazette.net/copying.html
Published in Issue 83 of Linux Gazette, October 2002

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]