Sunday, 30 March 2008

Adventures with Ubuntu: Mail

Setting up dovecot to work with Google Mail.

Given the choice, I prefer using an e-mail client in preference to a web browser on whatever machine I am using. Although Google Mail provides an IMAP service, I wanted to be able to keep a copy of my mail on my home server so that I could access Google Mail missives and my various other mail accounts from one source. I would also enjoy the benefit of having a copy of my mail in one easily backup-able and transferable source.

Installing dovecot and getmail:

sudo apt-get install dovecot-common dovecot-imapdc \
getmail4

Configuring dovecot.

Edit the file /etc/dovecot/dovecot.conf

Insert the line:
mail_location = maildir:~/Maildir
Restart dovecot:
sudo /etc/init.d/dovecot restart
You should get a reply:
* Restarting IMAP/POP3 mail server dovecot [ OK ]
Creating your mail directory.
cd ~
maildirmake.dovecot Maildir


Configuring getmail.


I have set up getmail to keep copies on the Google Mail server for 30 days. I figure that will give me enough resilience :-)

First, make sure that you have POP3 enabled on your Gmail account.
Click on your settings and select the Forwarding and POP/IMAP tab.



Create .getmail directory and rc file.
cd ~
mkdir .getmail
cd .getmail
chmod 700 .

Create a file getmailrc in ~/.getmail.

My getmailrc looks something like this:
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username = your.email.address@gmail.com
password = your_password

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

[options]
delete_after = 30
get_all = false

Next all you need to do is schedule getmail to run when you are not looking.

I have set mine to run every 5 minutes.
crontab -e
:
:
*/5 * * * * /usr/bin/getmail >/dev/null 2>&1

Connecting to your server.

This is the easy bit.

Using your favorite email client, create an account which uses IMAP. Your server will be localhost (or the IP address of your home server). The user id and passwords are the same as your Ubuntu user account.

Notes:

Because this is set up on my home network which sits behind a firewall, I have made no provision to employ secure IMAP connections which are, frankly, not needed in this instance as all connections to the IMAP server are made behind the firewall.