January 15, 2015

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"}++}'


Provide your email address when commenting and Gravatar will provide general portable avatars, and if you haven't signed up with them, a cute procedural avatar with their implementation of Shamus Young's Wavatars.

Re: What is my mail server rejecting?
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. ;-)
Posted 8 years, 1 month ago by FuguTabetai • @wwwReply

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title
Your Name:
Email Address:
Make Public?
Make Public?
verification image
Image verification:

Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.