Virtual Mail Domain User's Guide

    Overview

Given the practacality and popularity of virtual web domains it was only a matter of time before ftp and email services were offered. Hash table lookups via ruleset S98 are pretty well known by now, but I've yet to see a good implementation of a system that allowed everybody concerned to easily use virtual mail.

For those of us who weren't at class yesterday, virtual mail allows us to create a sort of forwarding table, that lets us map email addresses at a virtual domain to addresses elsewhere on the Internet. This allows us to do the following:

Say I have the domain `halo.net` (which I do), and I want to give all my friends email addresses @halo.net. I can't offer them accounts on the system, because I have too many friends and my computer isn't that big, but thats ok, because they already have too many accounts.

For our example, lets say I've got 5 friends who want to have @halo.net email addresses. Their email addresses are as follows:

(Ok, so I'm my own friend too...)

Each of these users wants their email address to be:

I can setup sendmail, using the virtual mail stuff, to deliver all email addressed to the various @halo.net addresses to the correspoinding email addresses. So all email addressed to `winter@halo.net` would be redirected and delivered to `winter@jurai.net`. Proper configuration of your email client software will allow you to send out email from your virtual domain address, and most people will never know you aren't using a shell or POP email account. Completely transparent.

I've written a simple system that allows virtual domain customers to manage their own mappings. It preforms sanity checking on the configuration files and allows users to be notified via email of configuration errors.

    Other Virtual Mail Resources

None yet. I'll fill in this section later.

    Files

The package I've put together to manage and automate the use of virtual mail domains has a few files that are responsible for automated processing of configuration files, and others that contain the configuration and data. Some files are generated automatically, others must be edited or executed from the command line or from cron.

    /etc/buildvirtual

This is a csh shell script that is usually run from cron. It runs makemap and processes the output of /etc/makevirtual. I could probably incorporate all of this functionality into /etc/makevirtual but this way its a bit more moduler. Eventually some of the things that happen in /etc/makevirtual should be moved here to allow /etc/makevirtual to become a bit more generalized.

    /etc/makevirtual

This file is a perl script that is called by /etc/buildvirtual or run from the command line. It processes the /etc/virtualdomains.conf and parses and processes the individual configuration files. It performs sanity checking on /etc/virtualdomains.conf and on the individual configuration files. It will check for changes within the last hour and send an email report of the processing of the individual configuration file to the virtual domain owner. This allow correction of errors. Any errors encountered in the processiong of the various configuration files will result in that operation being aborted and the next item being processed. Error messages will be printed in the /etc/virtualdomains file and mailed to the user if the file was changed in the last hour.

Note that /etc/makevirtual contains site specific configuration items that muct be changed in order for it to operate correctly.

    /etc/virtualdomains.conf

This file contains the configuration for each virtual domain to be sericed. Each line should have 3 space/tab delimited items on it; domain, the default username, and the location of the user configuration file. Invalid entries will be ignored. Comments using the '#' character at the beginning of lines are honored.

    /etc/virtualdomains

This file is generated by /etc/buildvirtual. It contains the raw mappings with comments and errors from /etc/makevirtual. It is used in the process of making /etc/virtualdomains.db.

    /etc/virtualdomains.db

This is the hashed database of mappings that sendmail uses for S98 re-writing. It is created by /etc/buildvirtual from /etc/virtualdomains.

    ~/username/domainname.email

These are the user configuration files that are specified in /etc/virtualdomains.conf. Comments are honored, invalid entries are dropped. The file contains mappings for the virtual domain in the form of: username validemailaddress, where username is the name of some user@virtualdomain and validemailaddress is a valid Internet email address.

    Setup

In order to use this system, you have to install and configure a few things.

    Sendmail Configuration

Add:
LOCAL_CONFIG
Kmaildomains hash /etc/virtualdomains.db


LOCAL_RULE_0
R$+ < @ $+ . >          $: $1 < @ $2 > .
R$+ < @ $+ > $*         $: $(maildomains $1@$2 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > $*         $: $(maildomains $2 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > .          $: $1 < @ $2 . >
to your sendmail .mc file and regenerate it. OR Add:
Kmaildomains hash /etc/virtualdomains.db
before the 'Options' section in your sendmail.cf and add:
R$+ < @ $+ . >          $: $1 < @ $2 > .
R$+ < @ $+ > $*         $: $(maildomains $1@$2 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > $*         $: $(maildomains $2 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > .          $: $1 < @ $2 . >
to ruleset 98. Remember that you need to restart sendmail for the changes to take effect.

    Installing Files

Copy the following files to the /etc directory. buildvirtual and makevirtual should be 755 root.wheel, and virtualdomains.conf should be 644 root.wheel.

    Crontab Entry

Add the following line to /etc/crontab. This will rebuild the virtualdomain database every hour. When you get a huge database, it may be wise to change this to run once every day. Eventually, the database will only be rebuild if any of the config files have been changed, so it won't matter how much you run it.
0       *       *       *       *       root    /etc/buildvirtual

    Configuration

Everything should be installed and working, but it won't do much until you change a few things and add an entry for your first virtual domain.

    Site Specific Configuration

In the /etc/makevirtual file, there are the following lines:
$this_host = "jurai.net";
$SENDMAIL = "/usr/sbin/sendmail";
$m_fullname = "Virtual Domains Subsystem Daemon";
$m_from = "virtual-domains\@intersurf.com";
$this_host should have the value of whatever the email address for the virtualdomain users is. $SENDMAIL should be the path to your copy of sendmail (ver 8.7.x is what I'm using). $m_fullname is the full name of the account that the reports are emaild from. $m_from is the email address that is to send out the reports. I've added an entry to my aliases file that direccts email addressed to this account to the proper place (me!).

    Adding a Virtual Mail Domain

Continuing our previous example, I'll need to setup the /etc/virtualdomains.conf so that I can use 'halo.net' as a virtual email domain. I would add the following line to /etc/virtualdomains.conf.
halo.net	halo	/h0/halo/halo.email
This will enable virtual mail for the domain 'halo.net', using the default recipient user of 'halo' and will look for the config file as '/h0/halo/halo.email'.

    Suggested DNS configurations

This is pretty standard stuff, but its worth mentioning it here. I usually have the following entries in the zone file for each domain.
halo.net	IN	MX	10 sasami.jurai.net.
halo.net	IN	MX	20 dim.intersurf.net.
This allows for email to be queued on dim if sasami is down. Sasami is the machine that my virtual domains in the example are hosted on.

*** DO NOT USE THESE EXAMPLES IN YOUR ZONE FILES! YOU WILL LOOSE EMAIL ***

    Considerations for Alternate Configurations

None at present.

    End User Configuration

Since the big goal of this whole thing is to allow the end user to configure and maintain their own virtual mail domains, they have to have some sort of configuration file to do their configuring on. :)

    The End User Configuration File

The end user configuration file is specified in the /etc/virtualdomains.conf file. This file should be owned by the user and the permissions set correctly. On processing '#' comments are honored and bogus input is not added to the final database. The user will receive an email with the status of the processing if he modifys the config file.

The config file has only two elements per line. A username and a valid Internet email address. By valid I mean an email address that is delivered to a shell or POP email account.

Continuing the above example, I would add the following to /h0/halo/halo.email:

winter	winter@jurai.net
zakk	zakk@intersurf.com
qwerty	coneill@oneill.net
siva	grendel@netaxs.com
huaman	abbyfg@tezcat.com
This would create the desired mappings as detailed above. When this file is processed, a default entry will be added using the values in /etc/virtualdomains.conf. This will map anything not matched to (in my case) 'halo@jurai.net'.

    Rules for Creating Mapings

    Explanation of Error Messages