Fetchmail and procmail setup [DEBIAN]

Find an article
Jul 5
Published by in · Leave your thoughts
( words)
Warning! There was an error loading some of the images for this post.

Having decided to start posting a range of computer science related  topics I thought it would be nice to explain how to setup fetchmail and procmail, which I personally use to, well, fetch my e-mails and then forward them on to my main e-mail account. I’m sure you know that having to login to multiple e-mail accounts is a huge pain and there’s typically only one that you truly care about and  go to on a regular basis. You may be thinking well Gmail for example lets you import accounts so why go to the effort of doing all this setup!? Sadly, some e-mail server administrators don’t like to provide the protocols that Gmail, for example, supports for e-mail imports…

Alright so let’s begin by installing the programs:

aptitude install fetchmail procmail

Next you should define .fetchmailrc in your $HOME directory (~/.fetchmailrc)

poll email.server
     proto AUTO
     user 'my@example.email'
     password 'mypassword'
     keep
     mda "/usr/bin/procmail -f %F -d %T";

Basically this is polling e-mails from the domain: email.server using the account my@example.email and the password mypassword. Proto is used to define the protocol you wish to use (word not port num), keep means leave the e-mail on the server and mda is what we use to forward the e-mail to procmail and onward to the interwebz! Optionally you can add other settings as explained: https://calomel.org/fetchmailrc.html

It was a while since I setup my configuration, so I can’t remember the reasoning behind doing such but I modified my poll line to include SSL:

poll email.server plugin "openssl s_client -connect email.server:993 -CApath /etc/ssl/certs"

With 993 being the SSL IMAP port for email.server

Now we setup the procmail config to deal with where we want to send the e-mail. Procmail is a remarkable little program that provides great flexibility in filtering out e-mails and such though the setup can be complex, the below gets us started with a basic forward (which is what I required at the time):

:0
* .*
{
        :0 c
        $DEFAULT

        :0
        !email.address.to@forward.to
}

Should you be interested in learning more about filtering with procmail see:  http://www.netikka.net/tsneti/info/proctips.php

To finish up we can add a cron job or run fetchmail in daemon mode:

*/5 * * * * /usr/bin/fetchmail >/dev/null 2>&1

Leave a Reply

Your email address will not be published.