If you’re very sure that you’re using a correct password and username (with @gmail.com after the user name), and not checking email in Gmail’s Inbox too frequently, you may need to clear and unlock the CAPTCHA. To unlock CAPTCHA for Gmail account, go to the following URL:
Note: For Google Apps user, visit https://www.google.com/a/
Type in the email address, password for the Gmail address, and fill in the correct Captcha validation. Click on “Unlock” button to fix the IMAP failure error.
For user who still faces the problem after clear the Captcha can try to use an alternative IMAP server instead, which is imap.googlemail.com on SSL port 993.