ALINK="#FF0000">
"Linux Gazette...making Linux just a little more fun!"
Setting up mail for a home network using exim
1 Introduction
Setting up a home network with Linux and Win95, using Samba, IP
Masquerading, and diald has been described many times, also in the Linux
Gazette, but so far I have not found a recipe for setting up mail on
a small network with only one dial-up e-mail account. In this article I want
to explain how I did it. With this system:
- users on the network can send local mail to each other, and
reply to it, also locally.
- outgoing mail has a proper From: address, so the outside world can
reply to it.
- the e-mail account is shared by the users, but each only receives
his/her personal mail.
This is realized on my system (running Debian Linux 2.1) using the
following programs:
- exim as the mail transfer agent (it is
much easier to configure than sendmail).
- fetchmail for collecting the mail from the ISP.
- pine as the mail client on the Linux side (but other clients can be
used as well, including mail).
- Microsoft Internet Mail on the Windows side (but other clients can be
used as well).
- qpopper as the POP3 server, for moving mail from the Linux system to
the Win95 machine.
I have this set up for two machines (1 Linux + 1 Win95) but it will
probably also work for a somewhat larger network, and may be sufficient for
a small office. Note: this article is Debian-oriented. If you use another
distribution, change where appropriate!
2 The network and the names
For this article I assume the following names (change these to
correspond with your own situation):
- the owner / system administrator is called Joe Bloggs.
- the Linux machine is called heaven.
- the Win95 machine is called earth. It is mostly used by Emily
Bloggs.
- Joe's user name on heaven is joe.
- Emily's user name on heaven is emi.
- Emily's user name on earth is also emi; her Linux password on
heaven and her 'password for Microsoft networking' on earth are the
same.
- Joe has a dialup account (dynamic IP address) with an ISP called
isp.com. Mail from the ISP can be collected using POP3.
- Joe's account name at the ISP is jbloggs.
- Joe's e-mail address (also used by Emily) is
joe.bloggs@isp.com.
- Joe's password for collecting POP3 mail is zaphod.
- The ISP's mail server (for sending mail) is smtp.isp.com.
- The ISP's POP3 server (for collecting mail) is pop3.isp.com.
- heaven and earth belong to a domain called home. This domain
name is meant for use only inside the home network; Joe has not registered
his domain name and it cannot be recognized by the outside world.
I also assume that the local networking works, and that there is on-demand
dialup access using diald. There is no name server on heaven.
/etc/resolv.conf contains the addresses of two name servers supplied by the
ISP. These same addresses are entered into the TCP/IP configuration on
earth.
/etc/hostname on heaven is
heaven
/etc/hosts on heaven is
127.0.0.1 localhost
192.168.1.1 heaven.home heaven
192.168.1.2 earth.home earth
On earth there is a file c:\windows\hosts with the same contents
as /etc/hosts.
3 Mail addresses
Mail messages can have more than just the address in the 'To:' and 'From:'
lines, for instance :
To: Emily Bloggs <joe.bloggs@isp.com>
'Emily Bloggs' in the above example is the 'real-name part'. It is set in
the e-mail program which composes the message. This 'real-name part' can be
used for delivering Emily's mail to her. Note: if the 'real-name part' has
dots in it, it must be quoted using " characters ("Joe C. Bloggs"). See also
man mailaddr.
4 Configuring exim
On a Debian system this is done by running eximconfig. It asks a
number of questions which you can answer as follows:
- your system is an Internet site using smarthost.
- the 'visible mail domain' is home
- other names apart from home and heaven.home: answer
heaven:localhost
- you don't want to relay for any non-local domains.
- you want to relay for the local network 192.168.1.0/16
- RBL (spam filter database): whatever you like. I said n
- The smarthost, handling outgoing mail, is smtp.isp.com
- System administrator mail should go to joe (not to
root!)
In MS Internet Mail (or whatever mail client you use on Win95) heaven
must be entered both as the STMP server and as the POP3 server. Under 'pop3
account' and 'pop3 password', enter the username emi and her Linux
password. Enter the the name, Emily Bloggs, and the e-mail address, emi@home,
in the appropriate place. Note that the e-mail address must be in the local
domain!
On the Linux side, nothing special has to be set. /etc/pine/conf and
the users' ~/.pinerc can be used 'out of the box'. The mail client (pine)
constructs local addresses using the hostname together with user information
from /etc/passwd.
With the above setup, local users can happily send mail to each other
and reply to it. For instance, in pine at heaven, user joe sends
mail to user emi. Automatically, pine changes this to:
To: Emily Bloggs <emi@heaven.home>
The message is delivered immediately (as you can see if you run eximon,
the exim monitoring utility). emi (should she log in to heaven)
would see the message as coming from
From: Joe Bloggs <joe@home>
So home really functions like a local domain within which messages
can be exchanged. The problem is sending messages to the outside world.
A From: address like <joe@home> is no good because nobody on
the outside could reply to an address in the non-existent domain home.
5 Fixing the From: address
We must change the local From: address into a valid e-mail address (the
e-mail account at the ISP), but only in the case of outgoing messages.
With exim, we can do this by means of a 'transport filter'. The outgoing
mail passes through this filter, and the From: address is changed. Local
mail will not be affected.
The following filter will do the trick, provided we are sure that
the address that we want to change is always between < and > signs. This
is not guaranteed, but very common: pine, mutt, and
mail, as well as MS Internet Mail all generate such addresses.
#!/usr/bin/perl
while (<STDIN>) {
if (/^From: /) {
s/<.*>/<'joe.bloggs@isp.com'>/;
print "$_"; last;
}
print "$_";
}
while (<STDIN>) { print "$_"; }
Don't forget to change the e-mail address to yours! Call this program
outfilt, do chmod +x outfilt and put it in
/usr/bin. Now we must add a line to /etc/exim.conf, so the
last lines of the TRANSPORTS CONFIGURATION section read:
remote_smtp:
driver = smtp
headers_remove = "sender"
transport_filter = "/usr/bin/outfilt"
end
Actually, we added two lines. The headers_remove line is
also new. This prevents exim from adding a Sender: header to the message (as
it would do with this setup, if you use pine). The Sender: line can cause
trouble with some (badly configured) mail destinations.
With these changes to /etc/exim.conf, whenever anyone sends an e-mail
message to the outside world it is now delivered properly by exim. Exim
(through diald) opens the outside line at once. In a home situation this is
probably what you want. In a small office, with a lot of e-mail traffic, you
may want to defer messages and send them as a bunch at certain times, to
save phone costs. This is possible, but I don't need it myself and have not
looked into it. You could look at the 'Linux Mail-Queue mini-HOWTO'.
6 Fetchmail configuration
At the command fetchmail diald opens the line and the mail from the
ISP is collected (and passed to exim for local delivery). Only users who
have a .fetchmailrc, owned by themselves, in their home directory
can run fetchmail. This file can be created using the configuration tool
fetchmailconfig. You get something like:
# Configuration created Sun Mar 28 03:15:20 1999 by fetchmailconf
set postmaster "postmaster"
poll pop3.isp.com with proto POP3
user "jbloggs" there with password "zaphod" is joe here options fetchall warnings 3600
The .fetchmailrc files belonging to the various users could all be
copies of each other, but with the ownership set to the user concerned. It
is not so nice that every user has the password in plain view. Maybe there
is a better way, but in a home situation it does not matter.
The main point is that whoever runs fetchmail, the mail must always
be delivered to the same user mailbox (joe's mailbox in
this case).
7 Removing exim's delivery limit
Exim by default does not deliver more than 10 messages at a time. I am sure
there are circumstances where this makes perfect sense, but having a dialup
account is not one of them. To get rid of this restriction, you must put
into the MAIN CONFIGURATION section of /etc/exim.conf,
before the end statement, a line
smtp_accept_queue_per_connection = 0
8 Delivering personal mail
Through fetchmail and exim, all mail from the outside
is by default delivered to Joe's mailbox (var/spool/mail/joe)
at heaven. In Joe's home directory he puts a file called .forward,
containing the following text:
# Exim filter
if $header_to: contains Emily then deliver emi endif
If mail contains 'Emily' in (the 'real name part' of) the To: address
(and this will almost always be the case when her friends send her mail) it
will go into her mail account on heaven, not into Joe's. She can move the
mail to her own machine using POP3 (see below).
9 Transferring mail with qpopper
To let heaven act as POP3 server for earth, qpopper can be installed. I
installed the Debian package qpopper_2.3-4.deb. Installation is
automatic; no configuration is necessary. If Emily presses 'get/send
messages' in MS Internet Mail, the contents of her mailbox on heaven get
transferred to earth (and all mail, local or outside, which she has written
gets delivered).
10 Manually checking the mail
Thanks to a 'shortcut' on earth's Win95 'desktop', which does a telnet to
heaven, Emily can log into heaven and start fetchmail by hand. That
is, if she does not want to wait for the scheduled cron times when
fetchmail runs. After the mail has been transferred from the ISP, she can
press 'get/send messages' to move any mail from her heaven mailbox into the
earth one.
Copyright © 1999, Jan W. Stumpel
Published in Issue 42 of Linux Gazette, June 1999