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 (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