E-mail collection

For a long time I’ve wanted a better home office e-mail system and I finally had some free time to set it up. It took a while. The information and tools are all freely available. But they are distributed in many different places and it’s difficult to find stuff when you don’t know what to look for. So I’m documenting my set-up here for future reference.

The first feature I wanted was to collect mail from multiple service provider accounts. My main account is on Google Mail but I’ve had others over the years and I also maintain a separate account for gamecontractor.org. I was tempted to forward all my mail to Google Mail and manage everything through a web browser. But I wanted a little more control over my data. In particular, I wanted more control over spam, archiving, and searching.

To collect my mail I found 2 programs that did what I wanted: fetchmail and getmail. I chose getmail because it seemed better documented and supported. The scripts to set-up getmail are even easy to read. Here’s my Google Mail script: .getmail/getmailrc-1:

type = SimpleIMAPSSLRetriever
server = imap.googlemail.com
username = ***
password = ***
mailboxes = ("INBOX", )

type = Maildir
path = ~/Maildir/

read_all = false
message_log = ~/.getmail/log
delete = true

Mail collected by this script is delivered directly to my Maildir folder. Maildir is one of the two most popular email storage formats (the other is mbox) and I chose it because it seemed more robust and easier to configure.

I have one of these scripts for each account and type of mail I need to collect. But getmail doesn’t collect my mail automatically. Each time I must run the getmail program with this script:

getmail -r getmailrc-1

However I can get the cron program to run getmail for me a regular intervals. The cron program was running automatically on my Ubuntu system so all I needed to do was add entries for my mail collections. I did that with the command:

crontab -e

This allows me to edit my crontab file which is a schedule of programs that I want to run. The schedule is a list with one entry per line. Each entry starts with 5 space separated numbers and then the command to start the program. The numbers represent: minutes past the hour, hour, day of the month, month, and day of the week. Any of these numbers can be replaced with a * which will match any value. The cron program will then call the program whenever the current time matches the numbers:

10 * * * * /usr/bin/getmail -r getmailrc-1 -r getmailrc-2

This line from my crontab collects my mail from two different accounts at 10 minutes past the hour.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.