Configure fetchmail and procmail to filter your emails

I got plenty of mail accounts and I have a laptop and a personal computer and I am tired of reading every mail twice. One time at home and one time on my laptop. So I want a mail system where I have to read my mails only one time. Imap seems to be promising to do this and since i got a server who is capable of imap i wanna configure it to get the mails into the right folders from my different mail accounts. And procmail offers a filtering system which can help me in automatically get the mails into the right folder.
1 answer

How to setup your imap server via procmail and fetchmail to filter your emails from different mail accounts

What do you need
--> linux server (Ubuntu can do the job http://www.ubuntu.com/GetUbuntu/download)
--> imap (http://ubuntuforums.org/showthread.php?t=57157)
--> fetchmail (http://fetchmail.berlios.de/)
--> procmail (http://www.procmail.org/)

How to configure
--> start a shell and log on your server

fetchmail
--> enter vim .fetchmail.rc
--> enter i to insert content
--> now you can add several servers
--> example: you have to edit content inside {} delete{} afterwards
#Server gmx
server pop.gmx.net
#protocoll
proto pop3
#
#User and Password
user {yourusername}
pass {yourpass}
#
#Options keep-> leaves messages on the server
keep
mda 'procmail -f-'
mda "/usr/bin/procmail -d %s"

#another server configuration
server mail.student.tuwien.ac.at
proto pop3
user {yourusername}
pass {yourpass}
#keep
mda 'procmail -f-'
mda "/usr/bin/procmail -d %s"

--> after you have finished your configuration enter ESC umschalt+:x enter to save the file

procmail
--> now we have to configure the procmail config to filter our emails
--> enter vim .procmailrc
--> enter i to insert content
--> now you can enter a bunch of filter rules
--> gilters are regex compatible (http://de.wikipedia.org/wiki/Regulärer_Ausdruck)
--> each filter begins with :0:, next line is the regex statement and the last line is the folder where you want to put your filtered emails.
--> example (you have to edit content inside {} delete{} afterwards)

MAILDIR=$HOME/mail
LOGFILE=$HOME/.procmaillog
:0:
* ^List-Id: {some mailing list name}
{foldername}
:0:
* ^To:.*{your email adress}*
{foldername}
:0:
*^To:.*
notfiltered
:0: spamassassin.lock
| spamc
:0:
* X-Spam-Level: \*\*\*\*\*\*
spam

--> after you have finished your configuration type ESC umschalt+:x enter to save the file
--> now we have to give that file the permission to be executed by the group
--> enter chmod u=rwx,g=x,o-rx .procmailrc

forward

--> now we have to edit the .forward file
--> enter vim .forward
--> enter i to insert content
--> enter |/usr/bin/procmail
--> after you have finished your configuration type ESC umschalt+:x enter to save the file

crontab

-->the last step is to make a cronjob, so that our mails are fetched from the servers and filtered every 6 minutes
--> enter export EDITOR=vim
--> enter crontab -e
--> enter i to insert content
--> example (you have to edit content inside {} delete{} afterwards)
# m h dom mon dow command
*/10 * * * * /usr/bin/fetchmail -s -f /home/{yourusername}/.fetchmailrc

--> after you have finished your configuration type ESC umschalt+:x enter to save the file

Finished! Now your mails get fetched from different servers and filtered into your MAILDIR into different folders and you can config your thunderbird to see your mails from everywhere.

Taggings: