Koozali.org: home of the SME Server

fetchmail & crontab combination

XAPBob

fetchmail & crontab combination
« on: August 31, 2006, 07:12:13 PM »
I'd been struggling to get me home SME server working for email.

Basically i wanted a box that would get my email via pop (from several boxes for me and other boxes for the rest of the family) and present it via IMAP and/or webmail.

SME server seemed great - but the multidrop email never quite worked for me.
So I installed two contribs:
Fetchmail - RPM (31-08-06) - To get email from multiple pop/imap sources.
Crontab - RPM (31-08-06) - To schedule jobs (like fetchmail more than every 5 minutes)

I also wroe a little script to ensure that fetchmail only ran once at a time and I got notified if it was taking too long:
Code: [Select]

#!/usr/bin/perl

use strict;
use warnings;

use Fcntl qw(:flock);

# File control: Locking prevents multiple instances running.
# Useful in case fetchmail takes longer than a minute to run.
flock(DATA, LOCK_EX|LOCK_NB) or die "$0 already running - did fetchmail take too long?";

# Now kick the mail retrieval process:

exit system("/etc/startmail");

# DATA section essential for locking - see top of file.
__DATA__


This does absolutely nothing other than call startmail if it isn't already running and pass teh return code back to the shell (or cron)

--
Setup
First set up the "e-mail retrieval settings" to multidrop, and the timings to "not at all" for all time periods.
Then set up fetchmail to collect one of your accounts - in debugging mode
open a couple of consoles on the SME server (via ssh if you want) and run:
Code: [Select]
tail -f /var/log/maillog
in one - keep watching this as it will tell you if your fetchmail config is correct.

In another run:
Code: [Select]
/etc/startmail

You should see a POP conversation in the log - you can now *unset* the debug mode for this account.

Then copy the code above into a file e.g /etc/safefetchmail and make it executable
Code: [Select]
chmod +x /etc/safefetchmail

Finally add the command to the crontab manager in the web interface.