I've tried several configurations on accessing my Gmail account (I just confirmed from gmail that IMAP is enabled, and I have accessed Gmail from my iPhone).

Among the settings I tried were:

Email address: christos.jonathan.hayward@gmail.com
Account name: Gmail
Account type: IMAP
Username: christos.jonathan.hayward@gmail.com
Email Server: imap.gmail.com
Password: [withheld]
Advanced settings: [Nothing checked]

When I click "Test Settings", I get a window that says:

Account Status
Gmail Failed
Error: Generic Test Failure
Note: If you continue to save, account will be marked inactive.
Press Cancel to return to editing accounts.