Jiff Slater
🤔 About
✍️ Contact
30 Jul 2021
These articles have been archived. You may find them useful but I am no longer offering support for them. Check out my latest articles on plkt.io.
Backing up your Gmail account using procmail and fetchmail
1 March 2012

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]
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



# Change ownership

chmod 600 ~/.fetchmailrc ~/.procmailrc

# Confirm that the configuration works
fetchmail -vk

# 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.