Rate limiting emails via SenderScore
I’ve just posted a bit of perl code to github with how to do what Comcast does to rate limit their inbound mail using the SenderScore database.
There’s a test script that can be called from the command line to show what is going on:
And is called by taking an IP address of a mail server, and getting the senderscore of said IP:
$ host smtprelay0123.a.hostedemail.com
smtprelay0123.a.hostedemail.com has address 216.40.44.123
$ perl t.pl 216.40.44.123 get
216.40.44.123:-1 => 0
This shows us that the reputation is “-1″ (not currently known) and the number of hits that this IP has this hour is 0.
If we execute an increment, it will populate the data:
$ perl t.pl 216.40.44.123 increment
$ perl t.pl 216.40.44.123 get
216.40.44.123:99 => 1
Which tells us that 216.40.44.123 has a score of 99, and that it has been incrememnted once in this hour.
Now, your policy server attached to your MTA can made a decision as to how many increments (mail deliveries) it wishes to honour, and either proceed with the transaction or return a 4XX series response.
Note, memcache will flush this entry at the top of the next hour. It doesn’t last for 60 minutes, but for the number of minutes remaining in the current hour.
Update: You can find an example of a postfix/perl policy server here
Categorised as: Email, Perl, Programming, System Administration, Uncategorized