Had the same problem and was able to fix this in two different steps:
1) Receiving Email -- Go to the Mail Preferences -> Accounts - Click on the amount in question and then Go to the Advanced Tab ... Check the Automatically Detect And Maintain Account Settings. After completing this step I was able to connect to my Gmail IMAP server and all the mail came in.
2) Sending Email -- Now that I could get my email, I still couldn't send email. A post in a different thread said to go to KeyChain and deleted all references to Gmail Passwords - both IMAp and SMTP Passwords. After doing this, go to Mail Accounts and deleted all Gmail accounts. Close Mail. Reopen Mail and then add the accounts back. Once this was completed, I was able to receive/send from all Gmail accounts.
My GUESS is that there is a bug that didn't take into consideration or know how to determine which SMTP password to use in Keychain. This likely of particular issue for those people who have done migrations from earlier OS X's or people who have added/deleted Gmail accounts multiple accounts.
Don't know is this will work for non-Gmail accounts.
YMMV, which means this will likely not work for everyone, but it did for me.