The most common questions I receive about the validrcptto.cdb patch involve how to create the validrcptto.cdb file in the first place, or how to use the same file on multiple servers. The mkvalidrcptto script can be a major part of the answer to both questions. This web page will show how I'm using mkvalidrcptto on my own server.

It should be noted that you are not required to use mkvalidrcptto in order to benefit from the validrcptto.cdb patch- any mechanism which produces a list of all valid email addresses on your system will work, even something as simple as manually editing a text file with one email address on each line. As long as you correctly turn this text file into a cdb file, it will work.

Before you install the script, there are a few other packages which need to be installed on the system. The first is djb's cdb library and tools, which contains the cdbmake-12 program, which converts a text file into a cdb file. This package should be installed using the directions on djb's web site. A quick walk-through is shown here:

So lets install it!


# cd /usr/ports/databases/cdb
# make install clean

Installing the CDB_File module

The mkvalidrcptto script reads several cdb files in order to do its job, which means that you need to install the CDB_File perl module, available through CPAN, the Comprehensive Perl Archive Network, which is an archive of Perl modules which are not included with Perl itself, but which others have decided to share in the hope that they will prove useful.

This is a quick walk-through of how to install the module.


# perl -MCPAN -e shell

If you have never run the CPAN shell before, just hit enter a few times and it will drop you right to the CPAN prompt.


cpan> install CDB_File

cpan> exit
# exit

Now to copy over validrcptto:


# cd /usr/local/bin
# cp ~root/qmail/mkvalidrcptto .
# chmod 755 mkvalidrcptto

One thing that wouldn't hurt is to make sure that your installation of perl is happy with the script and can find the modules. You can do this by running this command as a non-root user:


# perl -c /usr/local/bin/mkvalidrcptto


/usr/local/bin/mkvalidrcptto syntax OK

You should then run it once as root and make sure the output makes sense for your system. The output should be a list of every valid email address on your system, one on each line.


# mkvalidrcptto


alan@domain1.xyz
jms1@domain1.xyz
postmaster@domain1.xyz
thomas@domain1.xyz
@domain2.xyz
postmaster@domain3.xyz
user@domain3.xyz
...

Scripting for one system

The mkvalidrcptto script itself just reads the information it needs from your system and prints a list of email addresses. The other half of the equation is turning that list of email addresses into a validrcptto.cdb file, so that qmail-smtpd can use it. The original versions of mkvalidrcptto worked by simply printing the list of email addresses, and relied on another program called cdbmake-12 to produce the actual validrcptto.cdb file. However, as of 2007-06-06, mkvalidrcptto can write the validrcptto.cdb file by itself. This makes the scripting much simpler. The most basic way to create the validrcptto.cdb file would look like this:


# cd /var/qmail/control
# mkvalidrcptto -c validrcptto.cdb

The idea situation would be to have vpopmail run a certain command whenever it changes something. When John Simpson originally wrote this page, vpopmail did not have that kind of hook, however I have since written a patch for vpopmail called the ONCHANGE patch, which is officially part of vpopmail as of vpopmail version 5.4.15.

If you're reading this and understand how onchange works, you only need to run the "mkvalidrcptto -c validrcptto.cdb" inside the /var/qmail/control directory just once as once onchange is enabled, it will take care of any of the updates. I just wanted you as the user to understand how validrcptto works and understand it.

Now validrcptto is setup and configured. Later in the guide under configuring qmail we will enable validrcptto. Now to setup maildrop!