Checking Blacklisted Hosts with Mail::RBL

Mail::RBL eases the task of checking if a given host is in the real-time blackhole list. Mail::RBL does this by speaking directly to the RBL server and searching for a specified host. Ordinarily, you build this functionality into your MTA (sendmail, qmail, Exim, etc.), but if your system administrator hasn’t built RBL support into your MTA, you might consider integrating Mail::RBL into your own mail filter.

new( suffix )

Creates a list handle. suffix is required because it denotes the host from which you’ll check hostnames.

check($ host )

Performs the lookup against the RBL. $ host can be a hostname or IP address, without trailing netmasks (represented by a / followed by an octet).

For example:

use Mail::RBL;

my $host = q[some-spammer.domain.here];
my $rbl = Mail::RBL->new('list.org');

if($rbl->check($host)) {
    print "$host is in the RBL, and I won't deliver the mail."
} else {
    # Do something to deliver the email
}

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.