I am building a system which will connect to an email account, specified by the user, and download emails. The ImapClient class is getting stuck in an infinite loop when I attempt an SSL connection to an Exchange server where SSL is disabled.
When connecting with POP3, an IOException is thrown by the client which I can catch and handle, however the ImapClient catches and handles the exception itself and then appears to retry the connection indefinitely.
The following code sample is taken from the Aspose examples, I have added only
which is where the code enters the loop.
//Create an instance of the ImapClient class
ImapClient client = new ImapClient();
//Specify host, username and password for your client
client.Host = “exchange”;
// Set username
client.Username = “email@example.com”;
// Set password
client.Password = “password”;
// Set the port to 993. This is the SSL port of IMAP server
client.Port = 993;
// Enable SSL
client.SecurityOptions = SecurityOptions.Auto;
//Disconnect to the remote IMAP server
How should I handle this so that I can inform the user that the connection is invalid?