Search This Blog

Sunday, October 30, 2011

How to migrate mail from one Gmail account to another on Mac OSX, including Chats


This is the Mac OSX version of this article. The Windows version can be found here.

Recently at work, we got a new Gmail domain and had to switch from one Gmail account to another.

You can migrate your mail easily using POP3, but POP3 won't get your chats or preserve your labels. The superior solution is IMAP, even if it's a little more cumbersome. And even if you have already migrated using POP3, IMAP will still allow you to retrieve your chats and work for you on a tag-by-tag basis.

IMAP requires bit of a work-around—you must first fully download all your files to your machine, and only then can you migrate them back again into your new Gmail account.

Here's everything you need to get set up.

First, the downloads.
  1. Download the Mac edition of Mozilla Thunderbird and install on your machine.
  2. Download and untar the toIMAP files (we'll set these up later)
Now log in to your usual (old) Gmail account.

Then:

1. Click the gear icon in the upper-right corner and select Mail settings:


2. Click the Forwarding and POP/IMAP tab, scroll down to IMAP Access, and make sure it is turned on:


3. Click Labels and make sure that Chats and any other labels you want migrated are checked. (Note: If you already used the POP3 solution, you might want to limit only to Chats.)


4. Open Thunderbird, click Create a new account and use the address you want to pull the mail from, then click Continue:


Note: The wizard should smartly detect the proper settings; if not, you can click Manual config and enter the IMAP and SMTP settings shown below:


5. Click Create Account and let Thunderbird start downloading; this may take hours, and it goes without saying that the more mail you have, the longer the process will be. If you have to shut down for a while, to easily restart where you left off, just open Thunderbird, right-click, and click Get Messages in the context menu:


6. Log in to your new account and repeat steps 1 and 2 above for it. Make sure that you re-create any custom labels you used in your old account:


Now... go find something else to do for a few hours and come back to step 7 after Thunderbird (eventually) finishes.

7. Yay! Your e-mail finally downloaded! Rejoicing, right-click your account name, and click Settings (last option shown in the screen shot for step 5). Navigate to Server Settings, and copy the Local directory path at the bottom.


8. Open Finder, and select Go > Go To Folder, then paste the path you just copied. Keep this window open, as you'll need it for the following steps:


9. Open a new terminal window and type the following lines on your Mac:
cd ~/Desktop/toIMAP
vim toIMAP.cfg
i
The "i" puts you in insert mode; make sure your configuration file is set up like the one below, subbing in your username and password:
{
     'host' : 'imap.googlemail.com',
     'user':'YOU@gmail.com',
     'password':'YOURPASSWORD',
     'ssl': True
}
Then press ESC to exit insert mode, and type:
:wq!
to write and quit (save and exit) your configuration file.

10. Your configuration file is set; now all that is left is to run the file. Unfortunately, it does not appear that the script is smart enough to parse all folders at once, so you'll need to parse a single folder at a time, hence the opened Finder window in step 8 so you can reference each of your mail folders.

To run the file, you'll use the following convention while still sitting at the level in step 9:
python toIMAP.py -m path_i_just_copied/FOLDER_NAME -f FOLDER_NAME
For example, if I want to upload the folder "admin stuff" (shown in step 8), I would type (using a backslash to escape the space between "admin" and "stuff"):
python toIMAP.py -m ~/Library/Thunderbird/Profiles/76sexgps.default/ImapMail/imap.googlemail.com/admin\ stuff -f "admin stuff"
Some Gmail flags like Starred may need to omit the -f "admin stuff" part.

To specify a different Gmail tag than the name of the Thunderbird folder, just pass -f the new name, making sure that the tag already exists in your new account per step 5.

For example, to move your chats, you will not be able to use the same "Chats" name for your tag as that is reserved by Google. You'll need to create a new tag in your new account—I used "Archived Chats"—then import using the additional -f flag:
python toIMAP.py -m ~/Library/Thunderbird/Profiles/76sexgps.default/ImapMail/imap.googlemail.com/[Gmail].sbd/Chats -f "Archived Chats"
If your upload gets interrupted at any point, see the toIMAP directions on how to resume where you left off.

11. Repeat step 10 for as many folders as you need to migrate. Once you have gone through every folder you want backed up, you're done. Bliss is yours.

1 comment: