Sunday, 7 November 2010

"Unable to open connection to server" error when connecting to Exchange on Android 2.2

There seems to be a problem when using the default Android Email application to connect to an Exchange Server 2010 SP1.

When you go through the setup procedure and enter all necessary info to setup a new account on the phone, the setup will eventually fail throwing a "Setup could not finish" "Unable to open connection to server." message.

On the server side, the following log is generated:
 RequestBody :   
 <?xml version="1.0" encoding="utf-8" ?>  
 <FolderSync xmlns="FolderHierarchy:">  
 AccessState :   
 AccessStateReason :   
 ResponseHeader :   
 HTTP/1.1 449 Retry after sending a PROVISION command  
 MS-Server-ActiveSync: 14.1  

Google is aware of this ( and they calim to have fixed it but it is unknown when an update will be pushed.

The interesting thing though is that the Email application which is included with the 2.2 emulator seems to be working fine. So what we will do is extract the Email.apk from the emulator and install it on the phone.

Requirements: Rooted device, installed ADB and Android 2.2 Emulator.
Note: This will remove any improvements a ROM developer has included in Email.apk.
Disclaimer: I am not responsible if by doing this you damage your phone/data/life in an way. Backup your data first, preferably by making a Nandroid backup.

1. Make sure that any Android phones are unplugged from the computer.
2. Start the emulator using a 2.2 image.
3. After the emulator has finished loading, open a terminal and type:
 adb -e pull /system/app/Email.apk  
this will download the Email.apk from the emulator and place it in your current directory.
4. Close the emulator
5. Plug the problematic phone to your computer.
6. Make sure that USB debugging is enabled (Settings -> Applications -> Development -> USB debugging).
7. On the same terminal as before, enter the following:
 adb -d remount  
 adb -d pull /system/app/Email.apk Email.apk.bak  
 adb -d push Email.apk /system/app/
 adb -d remount  
 adb -d reboot  
This will temporarily remount the system partition as RW, make a backup copy of the original Email.apk to your hard drive (as Email.apk.bak), push the new APK to the device, remount the system partition as RO and finally reboot the device.

Thats it.

Now the phone should be able to communicate with the exchange server. If any problems persist, delete and recreate the account from the phone and remove the pairing from your exchange profile. Also, delete the Dalvik cache.

The original Email application will be in your home directory as "Email.apk.bak".


  1. That works indeed, thanks !

    Maybe a small improvement for your instructions.
    Every adb command for the emulator: adb -e
    And every command for the usb phone: adb -d

    By appending the -e or -d you can have the emulator and phone connected to the computer at the same time.

  2. Many thanks! I didn't know that.

    I will update the post when I get to a PC.

  3. Thank you for this tip! I'm new to Android and not a developer. Can you point me in the right direction to setting up the emulator? I have a Nexus One and would really like to use it with my work email. Or is it possible to update the email application without the emulator?


  4. Just for others who get here looking for a solution, I was running Cyanogenmod 6.1.1 on and HTC Aria, and had to boot to recovery (Clockwork Mod), mount the system partition, and then use the above instructions to get the push of Email.apk to work correctly.

  5. thanks
    it's working now

  6. thanks
    it's working now :) even account color :D

  7. Oh my god thank you so much, this just saved me from going back to eclair.

  8. Thanks for this approach but I pushed the APK, and flushed Dalvik but i still cannot connect.

    Have chatted to our Admin and my device was removed from exchange as well.

  9. OK, make sure you uploaded the correct APK (just in case).

    Remove the exchange account from "Menu->Account Settings"

    Then go to "Menu->Settings->Applications->Manage Applications->All"

    Find Email and click "Clear Data" and "Clear Cache".

    The open the application and recreate the exchange connection.

    See if it works then.

  10. I can't seem to get this to work properly.

    I am running android 2.2.1 and cyanogenmod 6.1.0-DS on my htc magic.

    I grabbed the apk from an android 2.2 emulator.
    I don't know how to 'remove the exchange account' and couldn't figure out how with Google's help.

    I did clear the dalvik cache as well as the data and cache of the Email app.

    Do you know what else I can try?

    1. I reflashed cm 6 with tiny gapps, and it worked.

  11. Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first”.