I'm trying to set up a mail server using OpenBSD, OpenSMTPD, spamd
, and pf
. The first problem I've encountered is that many large webmail providers - like Gmail - will retry delivery from a different server with a different IP address, making it hard for them to move pass the greylist into the whitelist. I've written a script that I thought might help by performing a PTR request on the IP of GREY tuples and comparing the resulting domain to a manually maintained list of domains I trust.
- First, is this a reasonable approach? What problems might I encounter?
- Second, why don't the GREY
records disappear from
spamdb
after I've whitelisted them viaspamdb -a X.X.X.X
and they then show up as a WHITE record? Once they're whitelisted, it should be for the entire IP and I imagine the GREY tuple is obsolete by that point. What is the typical life cycle of thesespamdb
tuples? I've seen some disappear, some duplicated (GREY then WHITE), etc. - Third, should I instead be writing these whitelisted IPs from my script to a file, then loading that file as a
pf
table which passes connections from those trusted domains directly tosmtpd
? In other words, rather than going throughspamd
and whitelisting these IPs withspamdb -a
which then get added to the<spamd-white>
pf table, should I just bypassspamdb
, leaving them greylisted, and go directly to some pf whitelist table.
Here's the draft script I wrote to be run periodically to automatically whitelist trusted domains that have been encountered and greylisted:
#!/bin/sh
set -A whitelist \
amazon.com \
google.com
spamdb | while read line
do
IFS="|"
set -A fields $line
status=${fields[0]}
if [[ $status = "GREY" ]]
then
ip=${fields[1]}
ptr=`host ${ip}`
IFS="."
set -A tokens $ptr
size=${#tokens[*]}
domain="${tokens[size-2]}.${tokens[size-1]}"
found=false
IFS=" "
for whitelisted in ${whitelist[@]}
do
if [[ $domain = $whitelisted ]]
then
found=true
fi
done
if (($found))
then
echo "+ $ip ($domain) has been whitelisted"
spamdb -a "$ip"
else
echo "- $ip ($domain) is unrecognized"
fi
fi
done
exit 0