Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use procmail to filter your inbound email Network
In response to a thread in one of the Apple fora, I've made a quick web page that tells in simple language how to use fetchmail to pull down your email so you can filter it with procmail, but still read it with the Mail application. This lets you use procmail's incredibly powerful filtering capabilities even if you aren't running a mail server. It will even work well with a dialup account.

[Editor's note: I can't say I've tried this one yet, but I hope to shortly. This looks like an easy to follow recipe for getting your own personal spam filter up and running.]
  • Currently 2.67 / 5
  You rated: 2 / 5 (3 votes cast)

Use procmail to filter your inbound email | 16 comments | Create New Account
Click here to return to the 'Use procmail to filter your inbound email' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
OK nice Idea
Authored by: Anonymous on Dec 16, '01 12:22:05AM

Can someone that understands *nix please translate this for me so I can try it? I would love to just bounce emails back that I know are spam without having to even click on them.

[ Reply to This | # ]
OK nice Idea
Authored by: silverghost on Dec 16, '01 03:38:43AM

Hi, I thought that osx mail has that bounce to sender feature.


[ Reply to This | # ]
OK nice Idea
Authored by: jimhill on Dec 16, '01 04:25:40AM

The basic idea is that the fetchmail program will connect to your mailserver and download your mail, then hand it all off to the procmail program. procmail will then take each message and check its headers and contents against a set of rules you set up and then ultimately dispose of each message according to the rules. If you want a great procmail-based utility to do this sort of thing, check out Catherine Hampton's SpamBouncer, at and enjoy.

For learning how procmail works, pick your favorite search engine *cough*Google*cough* and search on "procmail" and "tutorial". It's pretty simple, all told.

[ Reply to This | # ]
OK nice Idea
Authored by: silverghost on Dec 16, '01 05:57:34AM

Thanks ill go check that site right quick.


[ Reply to This | # ]
Authored by: Chas on Dec 16, '01 06:36:20AM

This tip is totally impractical since you have to rebuild your email box every time you read mail. It takes quite a while to rebuild my mailbox. And will no longer automatically put up the little red dot to alert you to incoming mail.Of course you could use PINE or some command line mail program, but that would be a huge step in the wrong direction.

BTW James, if you need help "translating" this from Unix, you should definitely not try this trick. Running a local mail system like Procmail is not for unix newbies, it is a security risk, and you could even open up your own system as a spam relay if you don't know what you are doing. So don't try this without expert help.

[ Reply to This | # ]
Not a security risk
Authored by: kwalker on Dec 16, '01 03:09:30PM

Procmail is not a "local mail system". It doesn't introduce any new security risks. It's syntax is bizarre and idiosyncratic, however, so using it's more advanced features is not for the faint of heart.

The perl module Mail::Audit is probably a better alternative for advanced mail filtering. (For simple mail filtering, just use, Eudora, etc.)

[ Reply to This | # ]
procmail is not a security risk
Authored by: bighouse on Dec 17, '01 01:48:03AM

Chas, procmail is a local delivery agent (LDA), it cannot send email and it cannot receive it either, all it can do is deliver it. It does not listen on any port for network connections. It cannot act as an open mail relay.

But you're right, security concerns should always be attended to! One of the goals of this excercise was to avoid starting sendmail, which does listen on port 25, and which can be configured as an open relay, and which has a history of security exploits (some recent). Apparently some people have been starting sendmail just to use access.db. I can understand their frustration, but unless they're well firewalled, I wouldn't recommend it...


[ Reply to This | # ]
is it really necessary?
Authored by: j|m on Dec 16, '01 11:17:36PM

what is wrong with setting up a rule in to send all messages that aren't either to or cc to your e-mail address to the trash? if you can pre-filter all of the mailing lists you know about, it's pretty effective against spam.
granted, it doesn't do an automatic bounce, but still. not having to read spam is almost as good as bouncing it back.

[ Reply to This | # ]
is it really necessary?
Authored by: hurls on Dec 17, '01 02:22:15AM

Not sure if it's really necessary, but unfortunately, the filters in (as far as i can tell, and i've been running OS X for only a week) can't handle compound statements like if to or cc isn't address1 OR address2. So people with multiple accounts can't easily filter out spam that way...

[ Reply to This | # ]
is it really necessary?
Authored by: ret on Dec 18, '01 10:52:11PM

I agree - the lack of an OR operation makes the Mail Rules primitive at best. What I'd also like to see is the ability to filter on Attachment content. Just to be able to bounce anything with a .pif attachment would be very handy at the moment.

And why does the auto-reply rule include the attachment, when the Reply button in normal use does not? I set up an auto-responder to tell people that they were afflicted with SirCam (and that the solution was to purchase a Macintosh ;-) but had to disable it almost immediately because I started getting responses from mail-servers that I was sending the virus on!

Even better, why not make the whole "Rules" preference pane a GUI front end to procmail and be done with it?

For that matter, why the hell doesn't the mail server filter out the known virii in the first place? That would be a boon for those of us still living with dial-up.

And yes, I have sent all these suggestions to MacOSX feedback.

cheers (and happy christmas)

[ Reply to This | # ]
polling multiple pop accts???
Authored by: rgray on Jan 24, '02 12:01:06PM

does one simply repeat the poll line for each of a series of multiple accounts? or is it more complicated than that?

[ Reply to This | # ]
is it really necessary?
Authored by: SeanAhern on Jul 06, '05 08:34:41AM
what is wrong with setting up a rule in to send all messages that aren't either to or cc to your e-mail address to the trash?

Nothing, as long as you never want to receive an email that someone Bcc:ed to you. That's a bit draconian.

[ Reply to This | # ]

Refreshing is easier than I thought
Authored by: bighouse on Dec 17, '01 01:25:22AM

Since I wrote this I've found that it is not necessary to rebuild mailboxes in order to see the new mail. You can quit & re-launch, or you can simply click on each of your mailboxes in succession. The web page has been updated to reflect this.

Also I can confirm that K Hampton's Spambouncer program works well in OS X, at least while running it in silent mode; configuring it is pretty easy.


[ Reply to This | # ]
OK, but the wrong destination...?
Authored by: el bid on Dec 17, '01 04:10:29AM

Fetchmail and procmail are definitely the right way to go, IMHO. But I think we're only doing half the job here, and confusing has the option to set up accounts that collect mail from a standard UNIX account, where the mail accumulates in /var/spool/mail/<username> (or /var/mail, which seems to be's default for this option). I believe that this is where fetchmail should be depositing the mail it collects. Then "Get New Mail", either from the Menu or as a button on the UI, will fetch mail from here. And I think the option to "Collect mail every <x> minutes" will also honour this.

el bid

[ Reply to This | # ]
Not Impractical
Authored by: Chas on Mar 29, '02 04:11:54AM

I withdraw my previous remark about this being impractical. I came upon this tip during a search, months after I made my original remarks. Apparently "Anonymous" rewrote his page with a couple of hints from the feedback, you no longer have to rebuild your mailbox to pick up mail, it now allows to automatically pick up the mail from the regular unix mailboxes. I believe this might have been an improvement in, it can now draw mail from the same standard Unix mailbox structure that native Unix apps like PINE use.
So I installed it and it works great. I will add a suggestion for Procmail spam filtering scripts, I tried Spambouncer and oh man is it great. I use to monitor procmail.log, it stays hidden and then pops up and shows me when procmail is filtering spam, I can watch it and see if there are any false positives, it saves messages tagged as spam and you can review them later. I must get 50 to 100 spams a day, it dumps them all in a separate folder, I could set cron to empty it every day (or week, etc).
So Mr/Ms Anonymous, thanks for the tip, it works great and I owe you one. Spam is gone from my machine. I have reclaimed control of my mailbox.

[ Reply to This | # ]
Spam filter for NON-beginners
Authored by: dennisbest on Jun 20, '02 03:15:05PM
I posted this hint for people with little or no experience.... or for power-users to help Mail users who have little experience.

If you want a comprehensive spam solution go to:

These instructions are easier than they look and, man, they WORK! Bye bye spam.

I'm reluctant to install this for others because I won't be around to troubleshoot. That's why I looked for a simple solution.

[ Reply to This | # ]