Tech Notes

Back to Gmail: Migrating emails from Google Apps mail to Gmail

This guide will help you migrate from your Google Apps email account to a Gmail account automatically using the (free) ‘imapsync’ software.

It is a common scenario for people to migrate their Gmail accounts to Apps mail accounts. There are more than many how-to guides and tutorials covering this direction of the migration. But how about the opposite.

There are many obvious reasons for someone to migrate (back) to Gmail from a Google Apps mail account. Google Apps mail is used by many organisations, schools, etc. Thus, when we leave from that organisation, it becomes a necessity to migrate all our emails elsewhere.
Google Apps mail to Gmail
So lets jump into this quick tutorial on how to migrate all emails from Google Apps mail to Gmail. There are few other mechanisms suggested across the internet, but the one that works smoothly is using “imapsync”.

“imapsync” software is a command line tool allowing incremental and recursive IMAP transfers from one mailbox to another. It is useful for Gmail account migration or account backups.


  • imapsync” was a free tool, but now the author is charging almost $45 for a copy. It is affordable for commercial use, but for personal use the price is an overkill.
  • The earlier versions of this software can be found on the internet and still be used without copyright violations. (DOWNLOAD the earlier version for FREE).
  • This guide is based on a Windows installation. The use can be easily adapted to Linux and other platforms as we will be compiling from the Perl source code and running the software. (Those who are on Linux, you could simply follow the install instructions with the download file).

Step 1: Install Perl

  1. Download and install “Strawberry Perl”. (Install to the default install location).
  2. Double-click and Run the “” batch file to add the environment variables.

Step 2: Setup the Prerequisites

  1. Open “CPAN Client” under Start Menu -> Programs -> Strawberry Perl -> Tools.
  2. Run the following commands individually:
    • install Mail::IMAPClient
    • install Digest::MD5
    • install Term::ReadKey
    • install IO::Socket::SSL
    • If this presents a warning with “Net::SSLeay could not find a random number generator” and “Do you REALLY want to continue? [Default: no]“, give “yes” and continue.
  3. install Date::Manip
  4. install File::Spec
  5. install Digest::HMAC_MD5
  6. install PAR::Packer
  7. At this point you should be all set with the Perl setup and the following command should not give any errors.
    • perl -mMail::IMAPClient -mDigest::MD5 -mTerm::ReadKey -mIO::Socket::SSL -mDate::Manip -mFile::Spec -mDigest::HMAC_MD5 -e ”

Step 3: Install ‘imapsync’

  1. Download the earlier version of ‘imapsync’ for free from here (or buy the latest version from here).
  2. Extract the downloaded file, if you can’t extract a tar.gz, use 7-Zip.
  3. Open the “build_exe” batch file in a Notepad and change the folder path to the extracted folder.
  4. Run the “build_exe” batch file.
  5. This should have created a “imapsync.exe”.

Step 4: Using ‘imapsync’

  1. Open “Command Prompt”.
  2. Change directory to the ‘imapsync’ folder.
  3. The basic ‘imapsync’ command is,
    • imapsync --host1 --user1 theoden ^
      --host2 --user2 ''
  4. For Gmail, change the following command with your Apps mail login and Gmail login details.
    • imapsync ^
      --host1 --port1 993 --ssl1 --authmech1 LOGIN ^
      --user1 --password1 password4user1 ^
      --host2 --port1 993 --ssl2 --authmech2 LOGIN ^
      --user2 --password2 password4gmail ^
      --split1 100 --split2 100 ^
      --reconnectretry1 30 --reconnectretry2 30 ^
      --noauthmd5 --noreleasecheck ^
      --timeout 1200  --allowsizemismatch
  5. Paste the modified command into the Command Prompt, ‘imapsync‘ should sync you mail accounts accordingly.
  6. It could take, hours (or days) to complete the sync, based on your internet connection speed and the amount of email in your mailboxes.
  7. For more ‘imapsync’ command reference run,
    • imapsync --help
  8. Once the sync is complete, you could also setup a forward all mails to the new Gmail account from the old Google Apps mail account.

This guide can look a bit more technical and for the ‘geek-handed’. If you follow the steps it should be straight forward.

However, if you are afraid you might burn your computer by doing this, just ask your friendly geek-next-door, and s/he should be happy to help you.

Happy migrating back to Gmail…!


18 replies on “Back to Gmail: Migrating emails from Google Apps mail to Gmail”

I am so glad you’ve included this tutorial on your site. I’ve been a Google Apps user since January 2008, but have been increasingly frustrated with each new “feature” Google rolls out that alienates the Google Apps userbase. We should be able to use services like YouTube and Profiles, among others, with our apps accounts. I am a diehard Google fan with Android phones, a tablet, a Logitech Revue and a heavy user of their services. Why do they have to mess with something good?

Anyway, rant aside, thanks. I’m trying it now to get my e-mail onto Gmail so the old and the new will be in one place. Then, I’ll forward everything going to my apps account to Gmail.

It doesn’t have to be this difficult.


I got as far as the Strawberry setup and changing the directory path in build_exe.bat, but I’m stuck at the next step. In CMD prompt, I tried to CD to IMAPsync as well as to IMAPsync-1.350 (I have it under c:IMAPsyncimapsync-1.350), but can’t get any commands to work. It’s been decades since I used command prompts. Any pointers?


You can verify your Perl installation by:

perl -v

If that is working, then for command prompt CD:

cd IMAPsync
cd imapsync-1.350

If this works, type the following and post the output here:

perl -mMail::IMAPClient -mDigest::MD5 -mTerm::ReadKey ^
 -mIO::Socket::SSL -mFile::Spec -mDigest::HMAC_MD5 -e ''

Your build_exe.bat should look like this:

Let me know if it works and if not what is the error you are getting, I’ll see if I can be of any help.


Thank you very very much for this guide.

A small note for Windows 7 users, Run CMD and Perl as administrator to avoid errors. One of them is a missing DLL error.


I tried to compile this for hours and it does not work. I keep getting errors issuing the perl commands. I also get perl unknow shell command. I have updated my environment variable for path. Please tell me which version of Perl I should download for my windows 7 64bit . I ran as administrator but I have problems. The command does not launch because it is not found. I have given up on this.


I’m presently using this to migrate 6Gb of emails from apps back to gmail. Yours was the only I found on the topic after a lot of searching, so great work there!

I went through the process yesterday and found that it didn’t quite work due to some changes which have taken place since you wrote the tutorial. I wrote up the below comment to share with your readers. I was hoping you might annotate the tutorial to include the below points in case others find them useful.

Thanks again!

— Begin My Comments —


Google Apps and Gmail now both have limits on daily IMAP upload and download limits. Not obeying these limits will block your account for up to 24 hours. Luckily the latest version of imapsync lets you specify how many MB to do in each instalment. Unfortunately the tarball you link to above is an older version which doesn’t support this feature, so other readers would be well advised to download the latest version. I just searched for imapsync online and found a few repositories which had the source code (github, etc).

2. You may want to specify that the test commend you use to test if Perl is installed (perl -mMail::IMAPClient –mDigest…) should be run from Windows Command Prompt, not within Strawberry or CPAN. Took me a moment to figure that out.

3. Still on the test command, I found when I copied and pasted it into command prompt, I got an error. It seemed to be caused by the very last character (the quotation marks). Deleting them, then typing them again (so the command looks just as you have it) made the command work without any errors. I think perhaps the HTML code gives a slightly different character to a normal set of double quotes.

4. Assuming you downloaded a newer version as per my instructions above, you will also need to run ‘install Authen::NTLM’ in CPAN, as this module is required by the new batch file . This makes the new test string a bit different (perl -mMail::IMAPClient -mDigest::MD5 -mTerm::ReadKey -mIO::Socket::SSL -mFile::Spec -mDigest::HMAC_MD5 -mAuthen::NTLM -e -mTime::HiRes ”) . Check out this file: for where I got this tip from

5. The version of PAR:Packer which came down when I tried to install it was not working, but I didn’t know that until I ran the build_exe.bat which gave me an error at the ‘pp’ step. I looked into it and found this thread: which tells you how to get a different version (I used 1.011) and build it yourself. Note, under strawberry you don’t use ‘make install’ but rather ‘dmake install’. That worked for me.

— End My Comments —


I ran into the same issue with pp, but I just ran cpan and ran install PAR::Packer

What would probably help is an unofficial portable build of strawberry perl with all of these modules pre-installed. Then, all we’d have to do is run the build_exe.bat for our environment.

I also noticed that if you install perl in a folder with spaces, you may have issues. just call perl and put it in c:\


I am presently trying to get my emails out of google apps and I have followed your instructions up to entering into CPAN, install IO::Socket::SSL. It seems to be stuck on this and won’t go on. The last line is
The cursor keeps blinking but nothing else is happening. Any reason for this? Should I just start over?


Very useful article.
I have installed and everything is working except the below error:

-msg INBOX/48482 could not fetch [4sc15qeds66add923sdfSAds 17154]: message_string() expected 17154 bytes but received 17454 you may need the IgnoreSizeErrors option

and when I see host2 inbox, some of the email migrated but only subject no main body content.

Does any one know what is this error? Please advise me.



Hello Nimal,

I need to migrate from Hosted exchange server to IMAP Server.. If you can tell me little procedure i.e. Ports used, credentials will be required or not etc.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s