With the advent of tools such as Amazon EC2, backing up your mail accounts is relatively easily.
Before you begin, make sure that POP is enabled in your Gmail account. You will need to log in via the web interface to confirm these settings.
To get started, launch an instance on your favourite cloud provider (or alternatively on your own computer). It’s wise to create a new volume to store your data.
Rationale: Fetchmail is used to retrieve the mail and procmail is used to create a Maildir — a much preferable format for storing messages because each message is stored in a seperate file.
# Preparing the storage volume
sudo fdisk [disk location]
sync
sudo mkfs.ext3 [disk location]
# Mount storage volume
mkdir -p ~/mail.com/username
cd mail.com
sudo mount [disk location] ./username
sudo chown -R ec2-user:ec2-user username/
# Install packages
sudo yum -y install fetchmail ca-certificates procmail
# Confirm that SSL connection works
openssl s_client -connect pop.mail.com:995
You should see Gpop ready for requ….
# Configure fetchmail
vim ~/.fetchmailrc
poll pop.mail.com
service 995
protocol pop3
username username@mail.com
password ‘password’
options ssl
# Configure procmail
vim ~/.procmailrc
MAILDIR=$HOME/mail.com/
LOGFILE=$HOME/pm.log
VERBOSE=on:0
username/
# Change ownership
chmod 600 ~/.fetchmailrc ~/.procmailrc
# Confirm that the configuration works
fetchmail -vk
C-c
# Download the mail
fetchmail -nk -a -d 200 -N
If you have a large mailbox, as expected, this will take a while. After it’s done, consider storing a copy of this volume (if using a cloud provider) elsewhere.