Blue Flower

Sunday, 05 July 2015 13:26

Configuring Validrcptto to fight spam

Written by
Rate this item
(0 votes)

Configuring validrcptto

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
This email address is being protected from spambots. You need JavaScript enabled to view it.
This email address is being protected from spambots. You need JavaScript enabled to view it.
This email address is being protected from spambots. You need JavaScript enabled to view it.
This email address is being protected from spambots. You need JavaScript enabled to view it.
@domain2.xyz
This email address is being protected from spambots. You need JavaScript enabled to view it.
This email address is being protected from spambots. You need JavaScript enabled to view it.
...

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.

It is possible to write a script like the one below, which can run as a cron job, in response to an ONCHANGE event, or as part of a general qmail-updater service, to rebuild the validrcptto.cdb file.


#!/bin/sh
PATH=/usr/bin:/bin:/usr/local/bin:/var/qmail/bin

umask 022
mkvalidrcptto -c /var/qmail/control/validrcptto.cdb

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 your validrcptto is setup and configured. Now to setup maildrop!

Read 2310 times Last modified on Monday, 17 October 2016 15:15

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.