A quick guide to migrating contacts, calendar, email and email filters from GMail (user@gmail.com) to Google Apps (user@domain.com).
Calendar Entries
- On GMail calendar, goto Settings -> Calendars -> Export Calendars to download a ZIP of your calendars in ICAL format.
- On Google Apps calendar, goto Settings -> Calendars -> Import calendar and import the ICAL entries to your calendar.
Contacts
To preserve contact groups, each group needs to be migrated individually.
- On GMail contacts, use the Export option to export each group in Google’s CSV format. Then export one more CSV of “Everyone (All Contacts)”
- On Google Apps contacts:
- Use the Import option to import the CSV of Everyone, leaving theĀ “Add these imported contacts to: ” option unchecked.
- Then use the Import option to import each group in turn, checking the “Add these imported contacts to: New Group… ” option, and enter the name of the group.
Google Sync
At this point you might want to switch Google Sync over to your Google Apps account. Follow the steps here, but enter your Google Apps email address instead of your GMail address. You then need to go through the steps here and sign in with your Google Apps account to select which calendars to sync. Remember to click the “Google Apps User?” link rather than trying to go through the normal GMail login page – your Google Apps email will not work there!
Email Filters
If you have any rules defined to filter/label your incoming mail, you can export these usingĀ “Filter import/export” in GMail labs:
- Go to Settings -> Labs and check “Enable” for the “Filter import/export” option on both your GMail and Google Apps account.
- In your GMail account, go to Settings -> Filters, click Select All and then Export, and save the XML document somewhere.
- In your Gogle Apps account, go to Settings -> Filters and then “Import filters”, select the file you saved in the previous step, and press “Open file”.
Email Delivery
You should now be ready to switch over your email. Hopefully your MX records already point at Google Apps and you have email forwarding set up from Google Apps to your GMail. If you don’t, you should set this up before you start trying to move your email.
Now is when you must commit to migrating by having all your new mail delivered to Google Apps instead of GMail!
- Login here, select “Manage this domain”, and ensure that in Users and Groups you have a user set up for the Google Apps email address you want to migrate your GMail to. If you created a group to forward the email address to GMail you will need to delete this group before you can create the user.
- Use the Inbox link at the top right to log in to the mailbox for the user (signing out if you are not currently logged in as that user).
- Send a test email to your Google Apps email address to ensure that you are receiving email correctly.
- Log in to your GMail account, go to Settings -> Forwarding and POP/IMAP and enable forwarding to your Google Apps address.
You should now be receiving all your email in your Google Apps mailbox. You may also need to update POP3/IMAP settings for any mail clients you are using.
Old Emails
The hardest part is now to migrate your old emails from your GMail mailbox to Google Apps. Google provide a number of officially supported options, however none of these are ideal – Mail Fetcher is only intended for new emails rather than migrating old emails, Email Uploader requires you to have all your email in Outlook, and IMAP Mail Migration requires you to upgrade to Google Apps Pro (but looks like a pretty good option other than that).
I decided to go for a free approach, using imapsync based upon these instructions. However I found that imapsync would frequently give up without copying the entire folder. I initially thought this was because the number of messages was too large, so I used the following script to split the mail into chunks by folder and also by date. I also tweaked the regexes to rewrite To/From/CC/BCC headers, and to be a little more tolerant of malformed headers:
#!/bin/bash
LOGFILE=imapsync.log
FOLDERS=( 'Folder1' 'Folder2' 'Folder3' 'Folder4' '...' 'FolderN' 'INBOX' 'All Mail' 'Bin' 'Drafts' 'Starred' 'Sent Mail' )
TIMES=( '--minage 1090' '--maxage 1091 --minage 999' '--maxage 1000 --minage 908' '--maxage 909 --minage 817' '--maxage 818 --minage 726' '--maxage 727 --minage 635' '--maxage 636 --minage 544' '--maxage 545 --minage 453' '--maxage 454 --minage 362' '--maxage 363 --minage 271' '--maxage 272 --minage 180' '--maxage 181 --minage 89' '--maxage 90' )
echo "Starting" > $LOGFILE
for FOLDER in "$@"
do
for ((j=0;j<${#TIMES};j++))
do
TIME=${TIMES[${j}]}
echo "" >> $LOGFILE
echo "*** $FOLDER $TIME ***" >> $LOGFILE
echo "" >> $LOGFILE
while ! ~/imapsync-1.267/imapsync --host1 imap.gmail.com \
--port1 993 --user1 user@gmail.com \
--passfile1 ./passfile --ssl1 \
--host2 imap.gmail.com \
--port2 993 --user2 user@domain.com \
--passfile2 ./passfile --ssl2 \
--syncinternaldates --split1 100 --split2 100 \
--authmech1 LOGIN --authmech2 LOGIN \
--include "$FOLDER" \
$TIME \
--useheader "Message-ID" \
--useheader "Date" --skipsize \
--regexmess 's/Delivered-To: user\@gmail.com/Delivered-To: user\@domain.com/gi' \
--regexmess 's/<user\@gmail.com>/<user\@domain.com>/gi' \
--regexmess 's/^((To|From|Cc|Bcc):.*)user\@gmail.com(.*)$/$1user\@domain.com$3/gim' \
--regexmess 's/Subject:(\s*)\n/Subject: (no--subject)$1\n/ig' \
--regexmess 's/Subject: ([Rr][Ee]):(\s*)\n/Subject: $1: (no--subject)$2\n/gi' >> $LOGFILE 2>&1; do
echo "" >> $LOGFILE
echo "***** NOT COMPLETE - $FOLDER $TIME *****" >> $LOGFILE
echo "" >> $LOGFILE
tail -100 $LOGFILE | mail -s "Imapsync Restarting for $FOLDER $TIME" "user@domain.com"
echo -n "Sleeping..." >> $LOGFILE
sleep 1m
echo "Done." >> $LOGFILE
done
echo "" >> $LOGFILE
echo "***** COMPLETE - $FOLDER $TIME*****" >> $LOGFILE
echo "" >> $LOGFILE
tail -100 $LOGFILE | mail -s "Imapsync Complete for $FOLDER $TIME" "user@domain.com"
done
done
echo "**** DONE ****" >> $LOGFILE
tail -100 $LOGFILE | mail -s "Imapsync Complete" -c "user@domain.com"
The script writes to a logfile, and emails the last 100 lines upon completion. I found this useful as some messages could not be copied. After some debugging I was able to locate these by searching for the Message-ID in my GMail to discover that they were all old messages imported from Outlook which had corrupted headers (newlines inside the header, so the Message-ID could not be found by imapsync). Manually deleting the corrupted messages from my GMail allowed the sync process to complete.

5 Comments
By far the easiest way to migrate emails is using the IMAP Mail Migration tool in the Premier and Education editions.
You can get a free trial from Google, do the migration and revert to Standard Edition (free) within 30 days and pay nothing. I have done this many times for clients.
Another option is to use the free program at gmail-backup.com
Regards.
Paul Myatt
Hello James,
Can I recopy your doc in the imapsync FAQ or future wiki (with the reference url) ?
Thanks in advance.
Sure – feel free.
Easiest way by far is to use the POP feature:
1. In your Gmail account (From where you want to import all your emails to your Google Apps statndard account) go to ‘Settings’
2. Then click on ‘Forwarding POP/IMAP’ tab.
3. Then select ‘Enable POP for all mail (even mail that’s already been downloaded)select allow POP for all’
4. Now go to your Google Apps account.
5. Go to ‘Settings’
6. The click on ‘Accounts’ tab
7. In the section ‘Get mail from other accounts:’ Click on the link ‘Add a mail account you own’
8. A new window pops up, just follow the process of providing your Gmail Account information
9. Probably 2nd page into it, it will ask for username, password, etc. and it will have a drop down menu next to Pop server: select the 1st ‘pop.gmail.com’ in the list
10. do not check mark leave messages as gmail does not support it
11. Check mark label and give it a good label like: ‘My Gmail’ or something.
12. Then click Add Account and it will go through the verification. Once you verify the account. You are done.
13. Now you can go back to the inbox and you should see your ‘My Gmail’ label. Click on it and it should download all your emails from your Gmail account. Please note that you will loose all the emails in your Gmail Account.
14. Final step is to then go back to the Gmail Account and disable POP download and enable forwarding to your google apps email account.
Hope this helps all the google apps users out there. Google Apps ROCKS….
Please contact me at kimnkhan@gmail.com if you need google apps related support.
You can certainly do it this way, however I believe you would lose your labels and the starred/non-starred status of the messages which is why I chose to use imapsync. Also using imapsync allows you to transform the headers so messages sent to your GMail account will still say “To: me” rather than showing your old GMail address.