Return to introduction

Configure email for Linux on your home PC

1. Are you concerned ?

The aim of this short report is to help Linux users to configure their email system in a multi-user environment. Let's say that you have a PC in your house, that you access Internet with a modem and that you want to provide a email address to everyone in your family : this help is for you !
Maybe it is not so difficult to configure sendmail ... for a Linux freaks, but for the others, a starting point will certainly be appreciated. I think that Internet connection and email configuration is the basic functionality that a PC must satisfy.

This introduction provide the typical 'case' of somebody connecting to Internet with a modem (not permanently connected) through an Internet provider. This typical user have only access to one mailbox (the case of multiple mailbox is simpler) which he wishes to split in multiple mailboxes on his local computer. Since the typical user could frequently change of Internet provider and since he likes to keep only one email address, he use aliases which are only a 'redirection' from a email address to an other. Each local user have a different alias name on the alias server and that is based on this alias name that the local computer can redistribute the mail coming from a unique mailbox to different local mailboxes.

It's also very interesting to be able to write email's off-line. Once online, the mail of all the users are sent and the the mail for everyone is fetched. In one pass ... Think on your telephone bill.

2. Who does it works ? Follow the mail ...

2.1. The typical example

Suppose that you have only two users on your local PC, let's say Paul Dupont and Luc Jackson. The former has the login 'paul' and the last has the the login 'luc'. Through your local Internet provider, you have access to a POP3 mailbox. Your address for this mailbox is ''. Luc and Paul have subscribed an alias address, respectively and These aliases forward any received mail to your mailbox ''.

On the local PC, Luc and Paul have respectively the local addresses 'luc@linuxpc.localdomain' and 'paul@linuxpc.localdomain' where 'linuxpc' is the name you have chosen for your computer. Luc and Paul wish to read their mail with Netscape, through a local POP3 server. As they send a mail to an Internet address, they wish to be able to send this mail off-line. They also wish that the address that the recipient will see doesn't contain the name of your local computer (linuxpc) but well the name of the alias server domain ( So, if luc send a mail to '', 'somebody' will think that the mail come from ''.

This situation is illustrated in the following figure.

3. Sendmail configuration

3.1 /etc/

To build the sendmail configuration file, it is highly suggested to use the m4 tool. In the directory /usr/lib/sendmail-cf/cf, create a file .mc. For example, my file /usr/lib/sendmail-cf/cf/ contains the following :
divert(-1) Begin of a comment text
# This is the macro config file used to generate the /etc/
# file. If you modify this file you will have to regenerate the
# /etc/ by running this macro config through the m4
# preprocessor:
# m4 >
divert(0) End of a comment text
include(`../m4/cf.m4') Include a standard macro.
OSTYPE(`linux')dnl Include an OS-specific macro.
undefine(`UUCP_RELAY') The host will not accept UUCP addressed email.
undefine(`BITNET_RELAY') The host will not accept BITNET addressed email.
define(`confAUTO_REBUILD') Automatically rebuild alias file if needed.
define(`confTO_CONNECT', `1m') Maximum time to connect ???
define(`confTO_QUEUEWARN', `48h') The time you can send email off-line before sendmail send you a warning mail is set to 48h
dnl define(`SMART_HOST',`') Define a SMTP host where to send the outgoing mails. Because of the word dnl, this line is seen as a comment. In this case, sendmail will communicate directly with the destination host. If you prefer to use the SMTP server of your provider, please uncomment.
dnl define(SMTP_MAILER_FLAGS, e) Define the SMTP mail to be 'expensive' which means that sendmail try to communicate with the SMTP server only on demand. Because of the word dnl, this line is seen as a comment. If you prefer to use the SMTP server of your provider, please uncomment.
FEATURE(use_cw_file) Read the file /etc/ file to get alternate names for this host.
FEATURE(local_procmail) Use procmail as the local mailer.
FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db') This feature will cause certain addresses originating locally or from a 'generic' domain to be looked up in a map and turned into another form, which can change both the domain name and the user name.
FEATURE(masquerade_envelope) The masquerade is use to mask the originator of a message by replacing him email address.
masquerade_envelope instructs sendmail to masquerade the envelope sender and recipient as well as those in the headers.
GENERICS_DOMAIN(`linuxpc') Define a 'generic' domain.
GENERICS_DOMAIN(`linuxpc.localdomain') Define a 'generic' domain.
GENERICS_DOMAIN(`localhost') Define a 'generic' domain.
GENERICS_DOMAIN(`localhost.localdomain') Define a 'generic' domain.
MASQUERADE_AS(`') This causes mail being sent to be labeled as coming from the indicated host, here
MASQUERADE_DOMAIN(`linuxpc.localdomain') Normally the only addresses that are masqueraded are those that come from this host. The MASQUERADE_DOMAIN feature extends the masquerade to the specified host.

More information about the m4 configuration file at

3.2 /etc/mail/genericstable

For each 'generic host' (such as defined in /usr/lib/sendmail-cf/cf/, the user name (and optionally the domain name) of the sender is changed. The table contained in /etc/mail/genericstable describe which changes has to happen.
For example,

luc@linuxpc.localdomain Luc.Jackson
luc@localhost Luc.Jackson
luc Luc.Jackson

In order to create the database file /etc/mail/genericstable.db, one should type the following :
makemap hash /etc/mail/genericstable.db < /etc/mail/genericstable

3.3 /etc/aliases

Optionally, you may change the alias file. In this way, you could, for example, send a mail to '' locally (without domain name) and this mail would be directly delivered to 'paul'. So, add the following line on the end of /etc/aliases

Paul.Dupont: paul
Luc.Jackson: luc

After doing this, you have to rebuild the alias database. Type

3.4 /etc/

This is the file containing names of hosts for which we receive email. In our example,


3.5 Restart sendmail

As user root, type
killall -HUP sendmail

3.6 Check the permission of sendmail

If you want that every user is able to send the mail queue, you have to set the user ID on execution.
chmod a+s /usr/sbin/sendmail

4. Configuration of the POP3 server

4.1 Install the server, if needed

The POP2 and POP3 server daemon are name ipop2d and ipop3d, respectively. In the Redhat distribution, they are included in the package imap. You can check if this package is installed :
rpm -q imap

If not, look for a file named imap*.rpm on the installation CDROM and install it with
rpm -ivh imap*.rpm

4.2 /etc/inetd.conf

the inetd daemon is responsible for listening on the TCP/IP port and to start the appropriate daemon (dependent on the port number) when a connection is established. For example, the pop-3 service use the port 110. Every time one try to connect to the pop-3 service (on port 110), inetd will start ipop3d. In /etc/inetd.conf, be sure that the following lines are presents and uncommented :

pop-2 stream tcp nowait root /usr/sbin/tcpd ipop2d
pop-3 stream tcp nowait root /usr/sbin/tcpd ipop3d

4.3 /etc/hosts.allow and /etc/hosts.deny

The files /etc/hosts.allow and /etc/hosts.deny describe which hosts are allowed to use the local INET services. If you want that only the local host be able to access this service, set the following :

4.4 /etc/services

You have to make sure that the services pop-2 and pop-3 are defined. Check in /etc/services that the following lines are presents :

pop-2 109/tcp postoffice
pop-3 110/tcp

It make the association between a service name (i.e. pop-3) and a service number (i.e. 110).

4.5 restart inetd

To restart inetd, type
killall -HUP inetd

5. Configuration of fetchmail

5.1 Create .fetchmailrc

fetchmail fetches the mail on a POP3 server and redistribute the mail locally via sendmail. Each user (who must be able to fetch the mail for everybody) must have a configuration file .fetchmailrc in his home directory. In our example, it looks like this :

poll with protocol POP3 aka no dns :
        user dfzt12 fetchall with password kdwMlp45 to Paul.Dupont=paul Luc.Jackson=luc

The 'aka' is only used for multi-drop. In this example, it declares a DNS alias for ''. If you look at the fetchmail man page, you will read :

When fetchmail, while processing a multi-drop mailbox, grovels through message headers looking for names of the mailserver, pre-declaring common ones can save it from having to do DNS lookups.

The option 'no dns' prevents the multi-drop system from looking for domain name aliases (for each recipient). If this option wouldn't be specified, it should be possible that a mail cannot be fetched because one of the recipient has an invalid domain name.

The option 'fetchall' ensures that all messages are fetched even the message that you have already read.

5.2 Check the permission of .fetchmailrc

fetchmail won't work if the configuration file hasn't the appropriate permission.
chmod 0710 .fetchmailrc

6. Using sendmail and fetchmail

To fetch the mail and to redistribute it, a user can type

To send the mail queue, type
/usr/sbin/sendmail -q

To check the mail queue, type
/usr/sbin/sendmail -bp