The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
virtual hosting with sendmail 27 November 1999
Need more help on this topic? Click here
This article has 2 comments
Show me similar articles
Virtual mail is the ability of a box to handle email for more than one domain.   I'm already running several domains and websites on this box.  Now I'm looking at how I can manage the mail in a more efficient manner.
the problem
I host several domains.  Several people have accounts on my box.  The way it's set up now, mail sent to either or both arrive in Eric's mailbox.  In reality, I want only one domain to work for Terry.  All others should bounce.

I first searched the FreeBSD Mailing list archives to see what I could find.  With a search string of "mail and virtual" I found a reference to the sendmail FAQ.  DOH!  That's where I should have started in the first place.  Right there on the homepage there is a mention of Virtual Hosting.  It refers to which is what I used as the basic for this document.  Please read this article in conjunction with that URL.

sendmail configuration
I already had my DNS configured.  So, for me, the first step was sendmail configuration. 

Here is what I added to my .mc file.  I was already using the virtusertable feature.  So I didn't have to add that.  See the sendmail page for details.

# Things for virtual domains.  see 
FEATURE(genericstable, hash -o /etc/mail/genericstable)dnl

Note that the above path for genericstable differs from that supplied in the sendmail example.  Then I did the following:

# cd /usr/ports/mail/sendmail-8.9.3/cf/cf
# m4 ../m4/cf.m4 >
# cp /etc/
# killall -hup sendmail

This compiles the .mc file, copies it to /etc, then HUPs sendmail so it reads it.

/etc/mail/virtusertable - incoming mail
Here are the entries I added to /etc/mail/virtusertable.  Note that there is a tab between the address on the left and the text on the right.  Do not use spaces.		terry		error:nouser No such user here

After saving these changes, I issued the following command:

[root@ducky:/etc/mail] # makemap hash virtusertable < 

In this case, mail sent to will be delivered to the local user terry.  But mail sent to will fail.  This is good.   However, if I have another domain on my box, say, mail sent to will be delivered to terry's mailbox.  This is not good.   Apart from adding an "error:nouser" line for each domain/user combination, I don't know how to get around this.  Check back later.

Well, it's now later.  Here's what I'm doing for my incoming mail.  I use /etc/mail/virtusertable and I have a section within that file for each domain.  So I have something like this:

# owner-majordomo-nz-freebsd-org owner-majordomo-nz-freebsd-org       majordomo-nz-freebsd-org            marc		error:nouser No such user here

For, the first three entires are for are majordomo (the names on the right hand side will in turn be resolved by some other aliases, but that is beyond the scope of this example).  The mail for is delivered locally to marc's mailbox.  All other mail for this domain is rejected with an error message.

#  owner-majordomo-racingsystem-com  owner-majordomo-racingsystem-com        majordomo-racingsystem-com

For, only these aliases are allowed. I'm not sure what would happen for other mail for this domain.  But if it matched a local user, it would be delivered to them.  It's far better to have a wildcard alias for each domain (such as

#                           dan                   				 dan

For, mail for marc is delivered locally. Mail for se is delivered to  All other mail for this domain is sent to mar.

genericstable - outgoing mail
NOTE: this section applies only to messages which do not explicitly set the "From:" field.  So if you are using a mail client which sets this field, sendmail will not override it using genericstable.

The genericstable file controls the "from address" on outgoing mail [if it has not already been set].  Here is an example of the mail headers for terry before I added genericstable support.  I first sent a test message to someone at another domain:

echo 'test msg' | sendmail

The recieved message looked this like:

Date sent:          Sat, 27 Nov 1999 18:25:18 +1300 (NZDT)
From:               Terry Paterson <><> 

test msg

Well, terry isn't part of, although he does have an account on  But I don't want him looking as if he's part of my domain.  So tere's what I put in /etc/mail/genericstable (remember to use tabs, not spaces):


Note that the my path for genericstable differs from that supplied in the sendmail example.  I put my genericstable database in /etc/mail instead of /etc.  Therefore, when I make my genericstable database, I do so in the indicated directory:

[root@ducky:/etc/mail] # makemap hash genericstable 
                                                < genericstable

Then I used the same test message.  This time, the message arrived looking like this:

Date sent:      	Sat, 27 Nov 1999 18:37:23 +1300 (NZDT)
From:           	Terry Patterson <>
This is from observation.  It may well be wrong.  Confirmation would be appreciated.  Unless otherwise specified, the "From:" field contains the fully qualified host name of the box on which sendmail is running.  For example,  I don't like that.  I'd rather just have the domain name.

Under normal conditions, the mail headers contain the fully qualified host name of the box on which sendmail is running.  That is, the output from hostname.   To change this, you can use this feature:


In which case, the "From" and "Send reply to:" fields of outgoing mail will appear to be from

The above test message looks pretty good.  But closer inspection reveals something else.  If you look at the mail headers for the last test message, it will look like this:

Return-Path: <>
Received: (qmail 24380 invoked by alias); 
  27 Nov 1999 05:44:27 -0000
Received: (qmail 24375 invoked by alias); 
  27 Nov 1999 05:44:27 -0000
Received: from (my.ip.add.ress)
  by with SMTP; 
  27 Nov 1999 05:44:27 -0000
Received: (from chuck@localhost)
	by (8.9.3/8.9.3) id SAA84718
        Sat, 27 Nov 1999 18:44:25 +1300 (NZDT)
Date: Sat, 27 Nov 1999 18:44:25 +1300 (NZDT)
From: Terry Patterson <>
Message-Id: <>
X-PMFLAGS: 33554560 0 1 P5C750.CNM

test msg

So I added the following line to my .mc file and recompiled it.  Don't forget to HUP sendmail.


This changes the return path to be this:

Return-Path: <>
Other virtual sendmail references - Does not deal with .mc only .cf

Need more help on this topic? Click here
This article has 2 comments
Show me similar articles