Koozali.org: home of the SME Server

Obsolete Releases => SME 7.x Contribs => Topic started by: XAPBob on August 31, 2006, 07:12:13 PM

Title: fetchmail & crontab combination
Post by: XAPBob 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 (http://no.longer.valid/phpwiki/index.php/SME7Contribs):
Fetchmail (http://www.schirrms.net/sme/SMEFetchMail.php) - RPM (31-08-06) (http://www.schirrms.net/files/smeserver-fetchmail-1.3.4-09.noarch.rpm) - To get email from multiple pop/imap sources.
Crontab (http://www.vanhees.cc/index.php?name=CmodsDownload&file=index&req=viewdownloaddetails&lid=232) - RPM (31-08-06) (http://www.vanhees.cc/index.php?name=CmodsDownload&file=index&req=getit&lid=232) - 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.