March 19, 2007

Import mail into Gmail with the Gmail Loader

Author: Joe 'Zonker' Brockmeier

So, you've turned your back on traditional mail clients and get your mail fix via Gmail these days. The only problem is getting to all those old message that are stuck in your old email client. One way to stuff that old mail into your shiny and capacious Gmail account is to use Mark Lyon's Gmail Loader.

GML is GPLed and written in Python, and available for Linux, Mac OS X, and Windows. Most popular Linux distros install Python by default. You'll also need the Python Megawidgets, which may not be installed by default. On Ubuntu and Debian, you can just grab the python-pmw package:

apt-get install python-pmw

After installing that package, download the most recent version of GML and uncompress it in the directory where you'd like it to live. You should have three files: the Python script, a COPYING file, and the README file. You can open the README if you would like to get an overview of the utility. After that, just start GML by running:


GML only has a few fields you'll need to tweak before you can get started. The first, the SMTP server, defaults to one of Google's SMTP servers. If, when you first run GML, it doesn't seem to work, you might want to change the SMTP server from the default to one of the Gmail servers listed on this page instead. For instance, I switched it from to after my first attempt to load messages failed, and had better luck.

Gmail Loader interface - click to enlarge

You can also send messages through another SMTP server if your ISP blocks port 25. To do that, replace the Google SMTP server with your ISP's, and add the authentication information if necessary.

Next, find the mailbox that you want to upload by clicking Find and navigating to the file or directory you want to upload. Then choose the mailbox type and message type, and provide the Gmail account that you'd like to upload mail to. The GML interface provides a few hints as to the type of mailbox you might have depending on the client you use.

After that, click the Send to Gmail button and hang loose while the messages are copied to the server. The application has a two-second timeout between messages, so it will take a while if it's copying a large amount of mail. In that case, you might want to just start the job off before you step away from the computer for the day and check in again the next morning.

To test GML, I uploaded about 1,300 messages from one mbox-formatted mailbox to a Gmail account. It took several hours. I didn't see any problems with the mail after upload. Gmail seemed to get the conversation threads right after mail was uploaded, and the original message dates were preserved. For some reason, Gmail tagged quite a few imported messages as spam, but it's easy to herd the strays back into your inbox.

GML supports mbox, maildir, MH, and a few other mailbox formats. You also have two choices for mbox: normal or less strict. The latter is designed for mail saved by clients that don't necessarily follow the mbox format precisely. The docs don't say which clients, exactly, and I've had no problem with the standard mbox option. If you have trouble importing mail in mbox format using the normal mode, try less strict instead.

In addition to GML, Lyon has a suite of additional utilities that interact with Gmail. A few of the utilities seem to be a bit outdated, and several are Windows-centric. The most recent release of GML itself is a bit long in the tooth, though it works just fine; 0.5 was released in 2004 according to the README, but according to the site 0.6 is in development.

For folks who don't go for GUI utilities, Lyon still offers GML's 0.4 release, which is command-line only. You might also want to look at the Gmail Loader Enhanced, which includes a fix that makes GML resend emails if the SMTP connection is reset during the upload.

GML is a simple utility, and not one that you'll need every day, but if you want a simple way to archive all those pre-Gmail messages, then it's just the tool for the job.

Click Here!