Archived Forum Post

Index of archived forum posts

Question:

IMAP / Exchange Server LOGIN - Command Received in Invalid State

Nov 01 '12 at 15:10

The Imap.Login method fails and the Exchange Server returns an error indicating "BAD Command Received in Invalid State". What is wrong?


Answer

What it means is that the Exchange Server does not allow the login and password to be sent over an unencrypted TCP connection. The "invalid state" refers to the fact that the connection is not SSL/TLS. Modify your code to instead use the IMAP SSL/TLS port (993) by setting the Imap.Port = 993, and also set the Imap.Ssl = true (for implicit SSL/TLS). It is also possible to use explicit SSL/TLS by keeping the default port value (143), but set the Imap.StartTls property = true. Explicit SSL/TLS is where the client connects with an unencrypted TCP connection, and then prior to the login, automatically converts to SSL/TLS via the STARTTLS command (assuming the IMAP server supports the STARTTLS extension).