FetchMail

WebHome | UnixGeekTools | Geekfarm | About This Site

Pointers

Example

    poll server protocol pop3 user "myuser" password "mypass" sslproto "" antispam 451

    poll localhost
     port 1143
     protocol imap
     user "myuserid"
     password "mypassword"
     is localuserid
     mda "/usr/bin/procmail -d %s"
     keep

Daemon Mode

    # run fetchmail in background, fetch every 120 seconds
    fetchmail -d 120

Fetching in chunks

       -B <number> | --fetchlimit <number>
              (Keyword: fetchlimit) Limit the number of messages accepted from
              a given server in a single poll.  By default there is no  limit.
              An  explicit  --fetchlimit of 0 overrides any limits set in your
              run control file.  This option does not work with ETRN or  ODMR.

My fetchmail combo

I run fetchmail on my imap server from a cron job. It fetches mail for all my accounts.

# crontab
*/5 * * * * /usr/local/bin/fetchmail -vvv > ~/logs/fetchmail.log 2>&1

I use procmail as my mda:

# .fetchmailrc
poll hostname protocol pop3 user "me" password "mine" sslproto "" mda "/usr/local/bin/procmail -d me"

I don't like sending my email from fetchmail through sendmail because 1. sendmail is an incredibly huge beast, and 2. sendmail returns instantly allowing many mail processing processes to be spawned by fetchmail which can be very cpu intensive.

I use procmail to pass my email through SpamAssassin in order to rewrite the headers.

# .procmailrc
:0fw:spamassassin.lock
* < 256000
| /usr/local/bin/spamc

Then, procmail delivers my email to a perl script which uses Mail::Audit by adding this to my .procmailrc.

# .procmailrc
EXITCODE=
TRAP=$HOME/bin/filter.pl

This allows me to write all my filters in perl. I only do some basic filtering in Mail::Audit, but the filters catch a significant amount of my incoming mail (spam and mailing lists) and file them so I don't have to download them to Mail.app until I'm ready. This significantly reduces the amount of time and bandwidth it takes to download my email, and significantly reduces the cpu utilization of my PowerBook (since it doesn't have to process all that spam). I use mutt on the server to read through my spam and make sure there's no ham before deleting it.

I tried replacing my fetchmail setup using the popread script that comes with Mail::Audit. Unfortunately Mail::Audit has a memory leak. Geekfarm gets a decent amount of spam... Every now and then (e.g. after a power outage), thousands of emails would build up on the server. The memory leak in Mail::Audit eventually caused the process to run out of memory, after which unpredictable things happened. Also, I found that Mail::POP3Client 's memory utilization would grow to dozens of megs while fetching an attachment of a meg or two. This aggravated the memory leak problem, to say the least... I updated the script to exit when encountering the out-of-memory error, but then it had to restart frequently enough that it would take forever catch up (fetchmail+procmail is quite a bit faster). Eventually I had to give up on the all-perl solution.




Updated Sun Jul 23, 2006 12:11 PM