IMAP Login: BAD Command received in Invalid state.

This error can happen if you connect to an IMAP server without SSL/TLS (i.e. at port 143) but the server does not allow unsecure sessions.  Oddly enough, the Microsoft Exchange IMAP4 server will accept the connection, but will fail any login attempt with this error.  Here is a sample SessionLog:

Connecting to IMAP server at xxxx.com:143
> ----IMAP RESPONSE----
> * OK The Microsoft Exchange IMAP4 service is ready.
> ----IMAP REQUEST----
> aaab LOGIN "mylogin"
> ----IMAP RESPONSE----
> aaab BAD Command received in Invalid state.

The solution is to use port 993 w/ SSL/TLS. Do this by setting the Chilkat.Imap.Port property = 993, and the Chilkat.Imap.Ssl property = True prior to connecting.