Up SpamAssassin RelaydelayRelaydelay Patch Relaydelay Script Addlist Script

Installing Greylisting via RelayDelay
on an RPM-installed server
(see also http://projects.puremagic.com/greylisting/)

I am extremely grateful to Evan Harris and the community who have provided this tool for reducing spam input. These are notes from the procedure I followed for three different systems one weekend. Be sure to consult the INSTALL file from the relaydelay distribution first and foremost.

Here is a snapshot of my MRTG output the week I installed the greylist (got it working Saturday about noon):

The green represents the mail being rejected by spamassassin, and the blue is my total mail volume. Others have produced more valid statistical analyses, but I find the graphic compelling. Now you should be really stoked to get this working. Let's begin:

Obtain the relaydelay archive file from http://projects.puremagic.com/greylisting/releases/

Install the "sendmail-devel-x.y.z.i386.rpm" RPM that is compatible with your system.

Install or upgrade the MySql server. Version 4.02 or later is recommended. For example:

bullet
MySQL-server-4.0.18-0.i386.rpm
MySQL-client-4.0.18-0.i386.rpm
MySQL-devel-4.0.18-0.i386.rpm
MySQL-shared-4.0.18-0.i386.rpm
MySQL-shared-compat-4.0.18-0.i386.rpm

If you are installing the server for the first time, follow the instructions that whiz by during the server RPM install. Basically, you need to set a root user and password and make sure that my.cnf in the /etc directory has all the options you need. I used the file /usr/share/mysql/my-medium.cnf as a basis, your needs may vary.

Install or upgrade some  Perl modules, using RPMs or CPAN. I used the CPAN approach.

DBI: 

    perl -MCPAN -e 'install DBI'

DBD::mysql

    perl -MCPAN -e 'get DBD::mysql'
    cd /root/.cpan/build/DBD-mysql-2.9003
    perl Makefile.PL --testpassword="yourpassword" --testuser="root"
    make install
    (You should delete any files in this directory tree containing your password after the build)

Net::daemon:

    perl -MCPAN -e 'install Net::daemon'

Sendmail::Milter: 

    perl -MCPAN -e 'get Sendmail::Milter'
    cd /root/.cpan/build/Sendmail-Milter-0.18
    perl Makefile.PL /usr /usr/lib
    make install

Untar the relaydelay archive:

    tar -zxvf relaydelay-0.04.tgz

Change to the output directory:

    cd relaydelay-0.04

Edit the mysql.sql file to supply the correct username and password for the mysql database supporting the greylist. Then Initialize the database:

    mysql -p < mysql.sql

I have no idea how you are supposed to use the supplied script, "relaydelay.sh", to start relaydelay.pl. On my system the script hangs at the part where relaydelay.pl is launched, and even if I start it as a background task, nothing works. Fortunately, a patch exists, courtesy of Martin Walker from the greylist-users mailling list, which fixes up the perl script to run properly as a daemon. It even supplies an init script to get things going at bootup. And, even better, it lets you direct output from the perl script into a log file. Get the patch for daemonizing relaydelay from:

http://lists.puremagic.com/pipermail/greylist-users/attachments/20030904/b8dafed9/relaydelay-0.04.bin

The original post by the author of the patch is at:

http://lists.puremagic.com/pipermail/greylist-users/2003-September/000261.html

In case the original location disappears, I've put a copy of the patch here.

Copy the patch to the relaydelay-0.04 directory and run it:

    patch -p1 < relaydelay.patch

This will create a script named relaydelay which you should place in your initscripts (/etc/rc.d/init.d) folder. Make sure it is marked executable. At this point you can also copy the relaydelay.pl script into your /usr/sbin directory.

Edit the relaydelay.conf file to set the username and password to be the same as in mysql.sql. Also set the values for $verbose, $run_as_daemon, and $log_file as needed. For beginning use, I also recommend that the value $delay_mail_secs be set to -1, which lets servers retry immediately. Copy this file to your /etc/mail directory, make sure it is executable, and add it to your startup with:

    > chkconfig --add relaydelay

Now start up relaydelay:

    > /etc/rc.d/init.d/relaydelay start

Verify correct startup: 

     > ps -A|grep relaydelay.pl 

should yield: 

     6387 ? 00:00:00 relaydelay.pl

 

and: 

     > tail /var/log/relaydelay.log 

should yield: 

Loaded Config File: /etc/mail/relaydelay.conf
Using connection 'local:/var/run/relaydelay.sock' for filter relaydelay
DBI Connecting to DBI:mysql:database=relaydelay:host=localhost:port=3306
Spawned relaydelay daemon process 2229.
Starting Sendmail::Milter 0.18 engine.

Add the following line to sendmail.mc:

     INPUT_MAIL_FILTER(`relaydelay', `S=local:/var/run/relaydelay.sock, T=S:1m;R:2m;E:3m')dnl

Now restart sendmail. Watch the output in maillog and relaydelay.log to verify correct operation.

Edit whitelist.txt. Change the entry for 192.168 to the more limited value for your subnet (i.e. 192.168.10). I suggest removing the other private network entries here.

Get the script for importing whitelist and blacklist text files:

http://lists.puremagic.com/pipermail/greylist-users/2003-November/000327.html

or here:

If you got the script from the puremagic mailing list, edit it to add "my $run_as_daemon" and "my $log_file" to the variable list.

Import the supplied whitelist and blacklist:

    perl addlist.pl -whitelist 9999-12-31 23:59:59 < whitelist_ip.txt
    perl addlist.pl -blacklist 9999-12-31 23:59:59 < blacklist_ip.txt

Now keep an eye on things for awhile. At some point you should arrange for logfile rotation. There is a file here which you can drop into your logrotate.d directory.

Mayn Idea and the M-Light logo are trademarks of Mayn Idea Inc.
Copyright (C) 2009 Mayn Idea, Inc.
All rights reserved.

Last modified 01 Aug 2009