What is my mail server rejecting?

I’ve recently migrated my hosting from one VPS to a new host. It was a lot more work than it should have been. I’ll try to be much better at keeping my host up to date and maintained.

At any rate, I finally have my mailserver up and running on the new host. I implemented greylisting and some other spam prevention measures. Sometimes I wonder what is being rejected and why. Here is a super simple perl one-liner that can look at the mail.log file and spit out what hosts are rejected, and what the rejection reasons are (independently.)

grep reject mail.log | perl -n -e ‘END { foreach my $key (sort {$hosts{$a} <=> $hosts{$b}} keys %hosts) { print “$hosts{$key}\t$key\n”; } foreach my $key ( sort { $reasons{$a} <=> $reasons{$b} } keys %reasons) { print “$reasons{$key}\t$key\n”;}} if (m/RCPT from (.*?): .*?: (.*);/) { $hosts{“$1”}++; $reasons{“$2”}++}’


Posted

in

,

by

Tags:

Comments

One response to “What is my mail server rejecting?”

  1. FuguTabetai Avatar

    This works better (matches more of the reject lines, and prints out something when it can’t match a line so I can go back and add that case in.)

    grep reject mail.log | perl -n -e ‘END { foreach my $key (sort {$hosts{$a} <=> $hosts{$b}} keys %hosts) { print “$hosts{$key}\t$key\n”; } foreach my $key ( sort { $reasons{$a} <=> $reasons{$b} } keys %reasons) { print “$reasons{$key}\t$key\n”;}} if (m/RCPT from (.*?): .*?: (.*);/) { $hosts{“$1”}++; $reasons{“$2”}++;} elsif (m/RCPT from (.*?): .*? Service unavailable; Client host .*? (blocked using .*?);/) { $hosts{$1}++; $reasons{$2}++;} elsif (m/RCPT from (.*?): \d\d\d \d+\.\d+\.\d+ (.*?);/) { $hosts{$1}++; $reasons{$2}++;} else { print STDERR $_; }’

    Also, while trying to post this I tracked down a problem that prevented the image verification word from actually showing up. Oops. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *