Setting up gmail in Mavericks - A connection error occurred

Just to compare the settings: (assumes you already Enabled the IMAP in the gmail).

  • Incoming Mail (IMAP) Server - Requires SSL

    imap.gmail.com
    Port: 993
    Requires SSL:Yes
    
  • Outgoing Mail (SMTP) Server - Requires TLS

    smtp.gmail.com
    Port: 465 or 587
    Requires SSL: Yes
    Requires authentication: Yes
    Use same settings as incoming mail server
    

Full Name or Display Name: [your name]

Account Name or User Name: your full Gmail address ([email protected]).

Google Apps users, please enter username@your_domain.com

Email address: your full Gmail address ([email protected]) Google Apps users, please enter username@your_domain.com

Password: your Gmail password


Update - Recommended Solution:

Upgrading to the latest Yosemite version, resolves the issue.


How I dealt with it prior to upgrading to Yosemite:

The way I managed to overcome this was by setting up a new email account for gmail in mail by using the Other account option, instead of the Google option.

I have no clue about what is wrong with the Google Account option in Internet Accounts of System Pref and the Email app, but going with the Other email account option worked flawlessly, and it even auto-discovered and configured the gmail iMap mail settings.

For others that might have similar issues here is a brief list to review:
- Make sure that iMap settings are enable.
- If 2step verification - create an App/Device password to use.
- Sometimes Google needs some guidance. Visit: https://accounts.google.com/displayunlockcaptcha from the machine you are trying to connect, log in to your account and follow the steps/instructions.
- Try the Other Account Option and even configure manually the gmail account in mail app if it can't auto-discover settings.