Squeezebox Setup

Install Mail Part 3 – Fetchmaill

As previously mentioned we are not going to install a local MDA (sendmail / postfix) to reduce complexity. So incoming mail will be fetched by fetchmail, handed to procmail, which will drop it into users inboxes. The first step is thus to check procmail is installed (it's part of the base package we selected in the main install, so it should be)

[root@tranquilpc ~]# which procmail

Says it’s installed into /usr/bin. If it’s not there you should install the base package – yum groupinstall base.

Next we need fetchmail itself:

[root@tranquilpc tls]# yum install fetchmail
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.sov.uk.goscomb.net
* updates: mirror.sov.uk.goscomb.net
* addons: mirror.sov.uk.goscomb.net
* extras: mirror.sov.uk.goscomb.net
squeezecenter-release | 951 B 00:00
base | 1.1 kB 00:00
updates | 951 B 00:00
addons | 951 B 00:00
extras | 1.1 kB 00:00
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package fetchmail.i386 0:6.3.6-1.1.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size

fetchmail i386 6.3.6-1.1.el5 base 526 k

Transaction Summary
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 526 k
Is this ok [y/N]: y

Fetchmail is not intended to be run as root, though it does offer a daemon mode. Really it should be cronned by individual users, but this means running cron, which I dont really want to do (logging!), so I'm going to ignore the dont run fetchmail as root advice. That means we need two bits of config. One is the main fetchmail config file, so create a new file /etc/fetchmailrc and add this to it:

set daemon 900
poll pop.gmail.com with proto POP3
user 'GOOGLELOGIN' there with password 'PASSWORDHERE' is james here
options keep ssl sslcertck sslcertpath /etc/pki/tls

Then chmod the file to root read only – it has a password in it.

[root@tranquilpc etc]# chmod 600 /etc/fetchmailrc

This config is saying that we want to run every 900 seconds, connect over POP3 to pop.gmail.com, setting our remote username and password, and mapping them to a local account (the account create when we starting running Dovecot earlier. If you are using a non ssl mail provider (just your ISP for example) then you can get rid of the ssl options (this part ssl sslcertck sslcertpath /etc/pki/tls of the last line). The keep option means that mail is not deleted from the remote server – useful in case you have a disaster. The next bit of config we need is a bit of service configuration. Create the file /etc/init.d/fetchmaild and put this into it:

# Startup script for fetchmail
# chkconfig: 2345 99 01
# description: A software package for fetching mail from remote servers.
# processname: fetchmail
# pidfile: /var/run/fetchmail.pid
# config: /etc/fetchmail

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
#[ ${NETWORKING} = "no" ] && exit 0

args="-f /etc/fetchmailrc --mda \"/usr/bin/procmail -d %T\" --nosyslog --silent"

# See how we were called.
case "$1" in
	echo -n $"Starting $prog: "
#	su fetchmail -s /bin/sh -c "$prog $args"
	daemon $prog $args
	echo -n $"Stopping $prog: "
#	su fetchmail -s /bin/sh -c "$prog --quit"
	$prog --quit
	/bin/rm -f $pidfile
	$0 stop
	$0 start
	echo "Usage: $prog {start|stop|restart|reload|status}"
	exit 1

exit $RETVAL

Note that we have specified --mda \"/usr/bin/procmail -d %T\" to send mail direct to procmail, and have set fetchmail not to log, and to be silent. Next we need to make the file executable:

[root@tranquilpc init.d]# cd /etc/init.d
[root@tranquilpc init.d]# chmod 755 fetchmaild

Finally we need to add fetchmail as a service:

[root@tranquilpc init.d]# chkconfig --add fetchmaild
[root@tranquilpc init.d]# chkconfig fetchmaild on

Before switching it on we need a procmailrc file too. You can create a system wide default in /etc/procmailrc, but it's probably better to have a file for each user. So in the users home directory (/home/james) for the user we've created) create a .procmailrc file that contains this:

#### Begin Variables section ####
# It is essential that you set SHELL to a Bourne-type shell if
# external commands are run from your procmailrc, for example if
# you use rc.spamassassin, rc.quarantine, or other advanced recipes.
# Setting SHELL should not be needed for the simple sorting recipes in 
# this step-by-step section, but to be safe and to future proof your
# procmailrc, set it anyway! Details are in Check Your $SHELL and $PATH.
# Directory for storing procmail configuration and log files
#You can name this variable anything you like, for example
# PROCMAILDIR, or don't set it (but then don't refer to it!)
# LOGFILE should be specified ASAP so everything below it is logged
# Put ## before LOGFILE if you want no logging (not recommended)

# To insert a blank line between each message's log entry, 
# uncomment the next two lines (this is helpful for debugging)
## LOG="
## "

# Set VERBOSE to yes when debugging; VERBOSE default is no

# Replace $HOME/Msgs with the directory where your personal (non-system-spool) mailboxes reside 
# Mailboxes in maildir format or served by Courier IMAP are often in $HOME/Maildir
# Mailboxes served by UW IMAP are sometimes in $HOME, sometimes in $HOME/mail, & sometimes elsewhere


#### End Processing section #### 

This file literally just sticks everything into your inbox. You can do clever things like add individual filters:

* ^TO_.*maillist@listserver.com.*$

For example would catch all emails sent to maillist@listserver.com and put them into your RandomFolder mail folder. Finally we can switch fetchmail on:

[root@tranquilpc ~]# service fetchmaild start
Starting fetchmail: fetchmail: WARNING: Running as root is discouraged.
[ OK ]


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: