Tuesday, February 28, 2012

How to connect Gmail to a Microsoft Exchange Server using Windows and DavMail

If you're religious about Gmail like me, but your University or work is dead set on Exchange, then this post is for you. Using this implementation I have fully functional send/receive capability with gmail as a client to my Exchange server.

Big thanks to Andrew Back for this post detailing how he got a similar setup going on Linux.

What you'll need:
  • A working gmail account.
  • DavMail
  • Java
  • An "always-on" internet connection and a computer you don't mind leaving powered up 24/7. Your PC will act as a gateway for gmail to connect to Exchange - when the gateway is powered off or disconnected from the internet, you won't be able to read your email with gmail.
Setting up DavMail
  1. Install DavMail.
  2. Open a terminal as an administrator and navigate to keytool.exe in the Java installation folder.
  3. Create a self-signed certificate using keytool. But don't just copy-paste the command they gave you: you need to set your own password.
  4. The self-signed key is created as davmail.p12 in the same folder. Copy it to the DavMail installation folder.
  5. Run DavMail. Make sure your settings look like this (they won't by default):
  6. Fill in your Exchange server's OWA address in the Main tab, and the password (you picked it in step 3) for the Key store password.
  7. You might want to uncheck "POP mark read" under the Advanced tab. "POP mark read" instructs the gmail client to mark emails as read on the Exchange server when they are downloaded and read in gmail.
  8. To verify everything is working, go to canyouseeme.org and make sure your local POP port in the DavMail server is visible. If it is blocked, you may be behind a firewall and will have to forward your ports.
  9. CanYouseeMe.org will also tell you your IP address. Write it down.
  10. Some kind of dynamic DNS (such as dyndns.org etc) is an excellent idea here as well. Without it, every time your IP address changes you will be unable to get your email until you reset gmail's SMTP and POP settings to match the new address. 
Setting up Gmail
  1. Log in to Gmail. Navigate to Settings -> Accounts and Import.
  2. Next to "Send mail as:", click on "Add another email address you own."
  3. Enter the email address from the Exchange server. Uncheck "Treat as an alias". (Click here for why.) Click next.
  4. Select the radio button "Send through xyz.com SMTP servers". Under SMTP server, enter your own IP address (you got it in Step 9) and set the port to 587. Enter your username and password normally. Check the "Secured connection using SSL" option.
  5. You should now be able to send email through Exchange with Gmail as your client. You might want to test it, but note that you won't be able to receive email until you complete the following steps.
  6. Go back to gmail settings. Under "Check mail using POP3:" hit "Add a POP3 mail account you own". The process is pretty much the same. Enter your Exchange username and password. Set POP server to your IP address (again, Step 9) and the port to 1110. Check "Always use secure connection (SSL) when retrieving mail." You probably want to check "Leave a copy of retrieved message on the server". Otherwise, gmail will automatically delete messages off the server the instant they are downloaded to your gmail account. (Then again, if your institution is forcing you to use Exchange, they're so evil they probably gave you a tiny email quota too; in that case, you might want to leave it disabled so the account on the server doesn't fill up.) Hit Add Account.
  7. You should now be able to receive email from Exchange through your Gmail account as long as the PC with DavMail remains online.

4 comments:

Unknown said...

How might one do this on the mac?

Anonymous said...

These instructions are great, BUT...gmail no longer accepts self-signed certs.

I got as far as Sending email via gmail via davmail via exchange. But receiving via POP wouldn't work w/o a valid CA cert.

Anonymous said...

Use Davmail with Fetchmail and Procmail linux tools to automate the whole process. Fetchmail fetches and chained procmail process forwards to gmail. This way, no setting is required on Gmail. Emails would just arrive there :)

jade said...

After doing some research I figured out that only devices running stock Android gmail login

Labels