When trying to Migrate email with Google Apps you will see the following error.
Failed to connect to IMAP server. Failed to connect to imap.gmail.com IMAP server
1. Verify that IMAP is not disabled for all of your users by following the steps below.
A. Sign in to the Google Apps administrator control panel.
The URL is https://www.google.com/a/cpanel/primary-domain-name, where primary-domain-name is the domain name you used to sign up for Google Apps.
B. Click the Settings tab and then select Email in the left column.
C. Under POP and IMAP Access, select or clear the check box for Disable POP and IMAP access for all users in the domain.
If you select the check box, POP and IMAP are fully disabled for all users in your domain.
Users cannot access POP and IMAP settings in the Gmail interface.
Users cannot access their mail via POP or IMAP even if they originally had it on.
Users cannot access or search mail via Google Desktop (which uses POP).
If you clear the check box, POP is enabled for your users, but IMAP remains disabled.
NOTE: Users need to enable IMAP in the Gmail settings under Forwarding and POP/IMAP.
Note: It may take 15-30 minutes for global IMAP and POP changes to take effect.
2. Within your job file make sure that you are not appending the domain name as On Demand Migration for Email will automatically do this and can cause this error also.