Hacker News new | past | comments | ask | show | jobs | submit login




Why use a homebrew Perl script for this when Postfix (and likely most other MTAs) has features available that can do this for you?

Want to block all mail from any domain name that's hosted by Cloudflare? That's simple enough (and doesn't require taking a shower afterwards, unlike when writing Perl).

Just grab the plain-text version of the file that contains the list of Cloudflare's IP address ranges [0], create a CIDR table [1] containing those ranges (followed by a "REJECT"), and add an instance of "check_sender_a_access" to your "smtpd_sender_restrictions" [2].

(Bonus points for taking a couple of minutes to write a shell script that runs once per day from cron, grabs the latest version of this text file, adds " REJECT" to the end of each line for you, and triggers a reload of Postfix if there were any changes to the IP ranges that it needs to know about.)

[0]: https://www.cloudflare.com/ips-v4

[1]: http://www.postfix.org/cidr_table.5.html

[2]: http://www.postfix.org/postconf.5.html#smtpd_sender_restrict...


Well, I definitely don't want to block any mail from cloudflare hosted domains, as I have many customers using cloudflare dns. I just want to delay it 15 minutes so that I can then do a second blacklist check. Does postfix do that?

>and doesn't require taking a shower afterwards, unlike when writing Perl).

I wouldn't say that. perl is about the best scripting language IMO, and is available on all systems.

I wrote my own spam filter because I want to have full control over how I deal with spam, and generally it works very well.


Postfix's "zombie blocker", postscreen [0] (which ships with Postfix), offers that functionality -- and more [1] -- out of the box.

In the worst case, where you have some unusual, specific need that hasn't been designed for, you can -- quite easily -- easily create your own policy daemon [2] (even in Perl; see the example) and/or milters [3].

> I wouldn't say that. perl is about the best scripting language IMO, and is available on all systems.

Oh, I agree; I was mostly teasing. I first started using Perl c. 1995 (and later, for writing CGI scripts, when CGI became a thing) and it is still the scripting language I reach for 95% of the time for basic sysadmin stuff.

> I wrote my own spam filter because I want to have full control over how I deal with spam, and generally it works very well.

I certainly can't fault you for that. Take a look at the greylist.pl script that ships with Postfix. It is an example of a policy daemon that implements greylisting (not meant for production; for greylisting, use postscreen instead). It's been several years ago but, after looking at that, I was able to implement my first policy daemon (which reached out to a MySQL server) in about 20 minutes and, after some testing, put it into production shortly after that. It's amazingly simple.

I'm not sure what MTA you are currently using but I would certainly recommend looking into Postfix. Back in the 90s, I was a hardcore, bigoted sendmail guy ("Give me sendmail or give me death!") but at some point I started looking into Postfix and have never looked back. Among other things, I manage mail systems at $work (an ISP) and I'm "very anti-spam". I occasionally need/want to do some unusual things policy-wise (WRT accepting or rejecting mail) and Postfix can itself handle 95% of it. For the other 5%, I tweak AMaViS or write my own policy daemons.

N.B.: My personal mail server (currently) runs on FreeBSD, where I use OpenBSD's "spamd" [4] for greylisting. Personally, I prefer and use that over postscreen (it stops upwards of 90% of remote mail systems from even getting to talk to the "real" MTA!) but on my (CentOS) Linux-based mail systems, I now just use postscreen (previously, I had a "standalone" OpenBSD box running "spamd" sitting in front of Barracuda appliances (as a transparent SMTP proxy). postscreen is really simple to get up and running -- and even more so if you're already using Postfix! -- and a very minimal, basic postscreen configyration will stop the majority of "zombies", hijacked PCs, blacklisted hosts, etc., from getting through to your actual SMTP server.

[0]: http://www.postfix.org/postscreen.8.html

[1]: http://www.postfix.org/POSTSCREEN_README.html

[2]: http://www.postfix.org/SMTPD_POLICY_README.html

[3]: http://www.postfix.org/MILTER_README.html

[4]: https://www.openbsd.org/spamd/index.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: