Setting up gmail in Mavericks - A connection error occurred I am trying to setup gmail on a clean install of Mavericks 10.9.5. The Gmail settings like enabling IMAP etc are all set.
So now I am ready to add a new account in my mac, by going in System Preferences -> Internet Accounts and click to add a new Google Account. 

Entering the email address and password and clicking the ok button, I am getting immediately an error message in red: "A connection error occurred".

I am trying the same directly in Mail app, still the same.
There is no 2step verification and all security settings in Google account are setup so the connection should work. I have also unblock access via the Google Unlock Captcha. But yet I am not able to create my account.

Also, if I try to use a wrong password or username, it immediately tells me that my credentials are wrong, so it seems like there is a communication with Google, but something goes wrong with the Auto-creation of a Google account.
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 (username@gmail.com). 

Google Apps users, please enter username@your_domain.com

Email address: your full Gmail address (username@gmail.com) Google Apps users, please enter username@your_domain.com

Password: your Gmail password