- Install the getmail tool. I'm running it under Cygwin on Windows, but it should run equally well on Linux. Here are the Cygwin steps:
- Run the Cygwin installer and make sure that you have python installed
- Make a directory for the getmail install: mkdir getmail
- cd getmail
- Download the latest release: wget http://pyropus.ca/software/getmail/old-versions/getmail-4.43.0.tar.gz
- tar -zxvf getmail-4.43.0.tar.gz
- cd getmail-4.43.0
- python setup.py install
- Log into the Gmail web UI of the account you want to archive
- Search for the files that you want to archive. E.g. to find all the files sent or received in 2011 search for: "before: 2012/01/01 after: 2010/12/31"
- Now we need to give all the search results a unique label. The trick here is that you need to label all the search results not just the first page, so:
- In the Gmail web UI click the select "all" check box
- When you do this, Gmail will ask "All 20 conversations on this page are selected. Select all conversations that match this search", click on the link to make sure you select all of them
- Click on the label icon
- Fill something unique in the "Label as:" box, e.g. "Mail2011"
- Click the "Create New" link
- The "New Label" dialogue box will pop up. Click "Create"
- A warning box will explain that this will affect all conversations in the search. Click "OK"
- Wait a few seconds until the "Loading..." box goes way to give Google time to make all its changes
- Next we need to set up a config file that will let you download all the selected emails
- First make a new directory for the archive
- mkdir emailarchive
- cd emailarchive
- Then edit a new config file
- vi getmail.conf
- Adapt my config to your use:
type = SimpleIMAPSSLRetriever
server = imap.gmail.com
username = email@example.com
password = topsecret
mailboxes = ("Mail2011",)
port = 993
type = Mboxrd
path = /home/dave/emailarchive/Mail2011.mbox
received = false
delivered_to = false
read_all = false
verbose = 1
- The next step is a gotcha, the archive file has to exist before you try to run the getmail program, so do: touch Mail2011.mbox
- You are ready to run the program now with:
getmail --getmaildir /home/dave/emailarchive --rcfile getmail.conf
- Some time later you will have all the emails downloaded to a local mbox format mail store
- Finally you can now go back into Gmail, select the label you created earlier and delete all the emails. Note that Gmail won't free up your space until the emails are emptied from your trash folder
If you need instructions on how to read mbox format mail store files take a look at these instructions for several different mail reading clients.
Thanks to Matt Cutts for outlining the general approach to Gmail archiving that I have adapted here.