July 2004, Ilker Temir
Using Fetchmail with Procmail
I decided to write this document after spending some time to come up
with a solution to integrate my existing procmail filtering system+IMAP
with my new accounts.
After doing some search on google I couldn't find anything that
explained this particular issue in detail and I had to spend some time
to find a usable solution. So I wanted to document it in case someone
else comes across such a problem.
After all there is not much to write since it is a pretty easy
First it may be good to briefly explain my system.
My primary e-mail account is on a unix system and I am using procmail
to filter the e-mails to approximately 40 different folders based on
"To:", "From:", ... fields. I then read the e-mails by using an IMAP
client. I store the e-mails on the server. This way I can read my
e-mails by using different clients on different systems and operating
systems. This is ideal for me since I usually need to use different
operating systems: Linux, Solaris and sometimes even Windows.
This makes it very easy to migrate from one e-mail client to another or
from one operating system to another. Of course, if you have a high
volume of e-mail traffic you will need quite a big quota to keep all
the e-mails on the server. However this may be ideal if you have
a 'modest' home network and/or you operate your own e-mail server.
When I needed to use additional e-mail addresses, I didn't want to
create additonal profiles in my e-mail client to retrieve the
e-mails from those accounts. 40+ folders are already quite difficult to
manage and there would be overlapping for multiple accounts. What I
wanted was to pass all these e-mails through my existing procmail
filter so that the messages would go to appropriate filters. All of the
rules in my .procmailrc are applicable to all the e-mail addresses I
A simple "forward" from other accounts to my primary e-mail account
would normally work perfectly but this was not possible in all
cases due to different reasons.
Then the solution would be automatically downloading all the e-mails
from my POP/IMAP accounts and send them to my primary e-mail
address. This is why Fetchmail is used for. There are several ways to
achive this, each way has its advantages and/or disadvantages depending
on what you are trying to achieve. The way I preferred was to use
fetchmail to download the e-mails and then pass them to procmail
directly, instead of sending them via local mail delivery.
After a short introduction here is what you really need to do.
First you need to make sure that your procmail is working properly. The
details of procmail configuration are beyond the scope of this
document. Refer to procmail homepage
for more information.
You can retrieve the e-mails by fetchmail with the following command or
similar. You will normally want to run this command on where your
primary e-mail address is stored.
[user-name] --proto imap --ssl --mda "procmail -f %F" --daemon 600
--logfile [logfile] [server-address]
NOTE: You should change the parameters of fetchmail as
necessary, for instance if you would like to use POP3 instead.
It will first ask you the password and then go into daemon mode and
retrieve all the e-mails from the server every 10 minutes by using IMAP
over SSL. It will then pass them to procmail (pay special attention to
"-f %F"), procmail will process them based on the configuration.
Please note that this example uses IMAP over SSL. You need to compile
fetch-mail with SSL support to be able to use SSL. It is not a
requirement, you can drop --ssl
parameter if you don't want to use it. Details of this are beyond the
scope of this document. Refer to fetchmail homepage for
more information. If you are a Debian user, you can try "apt-get
That is all. Of course you need to make sure that this process will run
without interruption. You may want to set a crontab entry to start this
process if there are chances for it to die (on a system reboot for
example). But then you will have to put your password in a readable way.
Carefully consider whether you really want to do it.