Previous Next Contents

9. Virtual Mail/Pop

9.1 Qmail Notice

This section applies to sendmail only. A section for qmail will be added in the next version of this HOWTO document.

9.2 Problem

Virtual mail support is in ever increasing demand. Sendmail says it supports virtual mail. What it does support is listening for incoming mail from different domains. You can then specify to have the mail forwarded somewhere. However, if you forward it to the local machine and have incoming mail to and they will go to the same mail folder. This is a problem since both bob's are different people with different mail.

9.3 Bad Solution

You can make sure that each user name is unique by using a numbering scheme: bob1, bob2, etc or prepending a few characters to each username dom1bob, dom2bob, etc. You could also hack mail and pop to do these conversions behind the scenes but that can get messy. Outgoing mail also has the banner and you want each subdomain's outgoing mail banner to be different.

9.4 Good Solution

Each virtual filesystem gives a domain its own /etc/passwd. This means that and are different users in different /etc/passwds so mail will be no problem. They also have their own spool directories so the mail folders will be different files on different virtual filesystems.

However, sendmail requires one minor source code modification. Sendmail has a file called /etc/ and it contains all machine names that sendmail will deliver mail to locally rather than forwarding to another machine. Sendmail does internal checking of all the devices on the machine to initialize this list with the local IPs. This presents a problem if you are mailing between virtual domains on the same machine. Sendmail will be fooled into thinking another virtual domain is a local address and spool the mail locally. For example, sends mail to Since's sendmail thinks is local, it will spool the mail on and never send it to You have to modify sendmail (I did this on v8.8.5 without a problem):

vi v8.8.5/src/main.c # Approximately Line 494
It should say:


Replace it with:

/* load_if_names(); Commented out since hurts virtual */

Note only do this if you need to send mail between virtual domains which I think is probable.

This will fix the problem. However, the main ethernet device eth0 is not removed. Therefore, if you send mail from a virtual IP to the one on eth0 on the same box it will delivery locally. Therefore, I just use this as a dummy IP ( I never send mail to this host so neither will the virtual domains. This is also the IP I would use to ssh into the box to check if the system is ok.

Edit /etc/ with the local hostnames.

vi /etc/

Create /etc/ like you would normally through m4. I used:

VERSIONID(`@(#)      8.5 (Berkeley) 3/23/96')

Edit /etc/ to respond as your virtual domain:

vi /etc/ # Approximately Line 86 
It should say:


Replace it with:

Sendmail cannot be started stand alone anymore so you have to run it through inetd. This is inefficient and will result in lower start up time but if you had such a high hit site you would not share it on a virtual box with other domains. Note that you are NOT running with the -bd flag. Also note that you need a sendmail -q running for each domain to queue up undelivered mail. The new sendmail.init file:


# Source function library.
. /etc/rc.d/init.d/functions

case "$1" in
        echo -n "Starting sendmail: "
        daemon sendmail -q1h
        echo -n "Starting virtual sendmail: "
        for i in /virtual/*
                if [ ! -d "$i" ]
                if [ "$i" = "/virtual/lost+found" ]
                chroot $i sendmail -q1h
                echo -n "."
        echo " done"
        touch /var/lock/subsys/sendmail
        echo -n "Stopping sendmail: "
        killproc sendmail
        rm -f /var/lock/subsys/sendmail
        echo "Usage: sendmail {start|stop}"
        exit 1

exit 0

Pop should install normally with no extra effort. It will just need the inetd entry for it with the virtuald part added. The inetd.conf entries for sendmail and pop:

pop-3 stream tcp nowait root /usr/bin/virtuald virtuald /virtual/conf.pop in.qpop -s 
smtp stream tcp nowait root /usr/bin/virtuald virtuald /virtual/conf.mail sendmail -bs

Previous Next Contents