Using fetchmail and procmail for maildir style storage from a pop3 account

For the longest time having POP3 messages stored in one large file bothered me. I found out however that you can easily convert the single file storage into Maildir style storage with fetchmail and procmail. Here are the steps I used to fetch mail from a POP3 mailbox and store the messages in Maildir style folders.

1. Fetchmail setup

The following configuration file for fetchmail will pop all the mail off the server and purge it so be careful. The main thing to notice is the mta line at the end that calls procmail.

[code lang=”ini”]
set logfile /tmp/fetchmail.log
set invisible
set no bouncemail

poll “mail.mypop3service.com”
protocol pop3
username “username”
password “password”
fetchall
nokeep
mda “/usr/bin/procmail -m /directory/to/procmail.conf”
[/code]

2. Procmail setup

This is a very simple Procmail configuration file. It stores everything in on directory called Mail. The main thing to notice here is that there is a / at the end of the directory.

[code lang=”ini”]
CORRECTHOME=/directory/to/store/mail/in
MAILDIR=$CORRECTHOME/
PMDIR=/directory/to/store/procmail/info/in
LOGFILE=$PMDIR/log
VERBOSE=on

:0
Mail/
[/code]

3. Running fetchmail

Now all you need to do is run fetchmail with the above configuration file:

[code lang=”ini”]
/usr/bin/fetchmail -f fetchmail.conf
[/code]

Doing this should result in a number of files stored in your Mail/cur directory if there are messages on the server.

2 thoughts on “Using fetchmail and procmail for maildir style storage from a pop3 account

  1. Umut Tezduyar

    Good job. It is working fine. I just tested it. I tried to access to the gmail. I had to add “ssl” to the fetchmail configuration file to enable SSL. That is all. Thank you

  2. George

    Great Tutorial. I had been meaning to do this for a while.

    My next step is to configure squirrelmail to present a web based interface to the imap server.

    Thank you for getting me started

Comments are closed.