Email Consolidation

From CafeWiki

Jump to: navigation, search

The issue here is that, like most people, the first email addresses that we got were POP email accounts from an ISP. There are some issues with this:

  • POP accounts are difficult to access from multiple places. Typically you end up with one Outlook mailstore (.pst file) on one computer that is inaccessible from any other computer.
  • Web access only works for emails that have not been removed from the POP server, coordinating the 'delete after' rules is necessary.
  • Checking email with a Smartphone or other mobile device compounds the problem.

In addition, relying on an ISP for your email becomes one more handcuff to hold you to that provider when there may be compelling reasons (financial, service level, moving out of the ISP's service area...) to change providers. Having your own domain and an IMAP mailserver provides freedom from these types of issues.

But, a cold-turkey switch from the old email address to a new one is sure to cause trouble with lost connections to infrequent contacts - those people that maybe only send and email to you at Christmas. It's hard to find and inform all of those people about a change of address with out missing some. So why not keep the old address (for as long as you want) and just have any messages forwarded to your new address?

One solution is to use the open source program getmail to retrieve your email from the POP account at the ISP and deliver it into the mailstore on your mailserver.

Install getmail

Obtain the getmail source (make sure to get the latest version of the software) and unpack it in a sensible location on your system:

$ cd /usr/src/
$ wget http://pyropus.ca/software/getmail/old-versions/getmail-4.20.0.tar.gz
$ tar -xzvf getmail-4.20.0.tar.gz

Build and install getmail as per the instructions on the getmail website or the README file in the install directory:

$ cd getmail-4.20.0
$ python setup.py build
$ python setup.py install

Configure getmail

For each user account on your mailserver for which you want to retrieve mail from a remote source, a getmail configuration file needs to be created that provides the information needed to allow the getmail program to retrieve email for that user. From the user's own account"

$ pwd
/home/username
$ mkdir .getmail
$ cd .getmail/
$ touch getmailrc
$ nano getmailrc 

In the editor add the following to the config file:

[retriever]
type = SimplePOP3Retriever
server = popserver.ISPname.com
username = username
password = password 

[destination]
type = Maildir
path = ~/Maildir/

[options]
# print messages about each action (verbose = 2)
# Other options:
# 0 prints only warnings and errors
# 1 prints messages about retrieving and deleting messages only
verbose = 2
message_log = ~/.getmail/gmail.log
read_all = false
delete_after = 15

The 5 bold items above need to be set according to your own requirements. The first three are self explanatory - use values that will actually get to your POP account email! The last two are more subtle, read_all = false tells getmail to only retrieve messages that have not been previously seen. If this is set to true (the default) then each message will be retrieve repeatedly until it is deleted from the POP server (delete immediatly upon retrieval is also a default of getmail). However, if you use a webmail interface to see your email as well, then leaving the email behind for a period of time might be desirable. The next configuration item, delete_after = 15, tells getmail to leave retrieved messages for a total of 15 days before the items are deleted from the POP server.

The destination section needs to match your IMAP store type and the logging should be set to a level that works for you. I started with verbose=2 in order to keep an eye on what was going on, it could easily be turned down.

Secure the configuration directory and file since it contains your username and password in clear text:

$cd /home/username
$chmod -R 600 .getmail

Running getmail

All good so far, but how to actually retrieve the POP mail? Easy:

$ getmail

And, magically, all the email in the POP account will be delivered to your local mailstore.

Unfortunately, if you've got a bunch of email in the POP account it may all end up being tagged with today's timestamp - somehow getmail doesn't preserve the original timestamp. I though about trying to figure this out but didn't bother as it only is a problem for the first retrieval.

All well and good, but you don't want to be logging into your mailserver account and running the command getmail every time you want to check the POP account. The answer is easy, use cron. Set up a crontab for the user:

$crontab -e

In the editor (pick nano if this is the first use of cron for this user) and enter

# m h  dom mon dow   command
11 6,9,12,15,18,20 * * * /usr/local/bin/getmail >/dev/null 2>&1

Which runs getmail at 6:11, 9:11, 12:11, 15:11, 18:11 and 20:11 everyday and discards the output. Pick times that work for you and you are good to go. (Note that 11 6-18/2,20 * * * would result in the same execution times for the cron job.)

Personal tools