Mail.app encounters recurring connection error (to Gmail IMAP server) after installing Mountain Lion I have a Gmail IMAP account in Mail, which up until installing Mountain Lion has always worked smoothly.

Now after the upgrade, I find that if I have Mail open for a while in the background or I put my computer to sleep while Mail is running, when I return to it, Mail shows the error:

"Unable to Connect 

There may be a problem with the mail server or network. Verify the settings for account "Gmail" or try again.

The server returned the error: The server "imap.gmail.com" cannot be contacted on port 993."

Here is a screenshot.

I've verified my IMAP settings are correct. The only way to fix it at the moment is to quit and reopen Mail. Then it breaks after a while and the process repeats!

Do you have any ideas why it might be doing this? I'm on an early 2011 MBP.
Thanks in advance for any help you can give!
This happened to me while in Snow Leopard. It's a different situation, however I fixed it by removing the mail account, and re-adding it fresh. Worked forever after that.

-Z