// Should now be in the TRANSACTION/Authenticated State
var nummessages = client.GetMessageCount(); // Throws Pop3Exception: “STAT failed:-ERR bad command”
client.Quit();
/* For IMAP
client.SelectFolder(ImapFolderInfo.InBox); // Throws ImapException
client.Disconnect();
*/
}
I don’t set the Username/Password fields until after the “client.Connect(false);”, because it seems like if I do specify them, the client tries to initiate the login anyway.
This approach also fails when passing legitimate login credentials as well.
Could you please try with the latest version of Aspose.Network for .NET 5.7? I could not reproduce the exceptions mentioned in the comments in above code.
By providing a valid user/pwd, there is no exception in calling first Connect(false) and Login() later.
But, by providing a bad user/pwd
exception is thrown on Connect(false) for IMAP
for POP3, Connect(false) works without exception, but Login() throws the login error exception.
Please find the attached sample project that I used for testing.
Could you please try with the latest version of Aspose.Network for .NET 5.7? I could not reproduce the exceptions mentioned in the comments in above code.
By providing a valid user/pwd, there is no exception in calling first Connect(false) and Login() later.
But, by providing a bad user/pwd
exception is thrown on Connect(false) for IMAP
for POP3, Connect(false) works without exception, but Login() throws the login error exception.
After upgrading to 5.7, you're right, the POP3 Connect, then Login works as expected. But, the IMAP version still does not handle this correctly.
Also, with both, I have to specify the username/password in the constructor, rather than setting the properties after the Connect call.
Also, with both, I have to specify the username/password in the constructor, rather than setting the properties after the Connect call.
The sample which I attached is based on your example. It
Calls Connect(false)
Sets user and password
Calls Login()
All 3 steps worked fine at my end with correct user/pwd, without any exception.
If we remove the username/password from the constructor, then the first client call after the .Login() call throws an exception: using (var client = new Pop3Client(host, port)) // No username/password here { client.SecurityMode = Pop3SslSecurityMode.Implicit; client.EnableSsl = true; try { client.Connect(false); } catch (Exception ex) { Console.WriteLine("Connection Error: " + ex); return; } try { client.Username = username; client.Password = password; client.Login(); } catch (Exception ex) { Console.WriteLine("Login Error: " + ex); return; }
// The server must implement this command Console.WriteLine("Connection Success: {0} messages", client.GetMessageCount()); //This throws an exception
I have reproduced the issue now. Sorry for overlooking previously. I have also logged these issues in our issue tracking system (ID: 20655 and 20656) for both POP3 and IMAP. We will look into these and will get back to you as soon we have any solution or other feedback.
The issues you have found earlier (filed as 20656;20655) have been fixed in [this update ](http://www.aspose.com/community/files/51/.net-components/aspose.network-for-.net/entry264900.aspx).
It’s a problem around which we can work, but it seems like in the ImapClient class, calling “client.Connect(false);” will behave differently depending on setting a username/password before calling it or afterward.
The following works how I would expect:
client.Connect(false); client.Username = “BadUser”; client.Password = “BadPass”; client.Login(); // Throws ImapException, which we would expect
But, if I change the order, it appears that the “Connect(false)” call tries to validate the credentials:
client.Username = “BadUser”;
client.Password = “BadPass”;
client.Connect(false); // Throws ImapException here client.Login(); // We would expect the ImapException here
The issues you have found earlier (filed as 21264) have been fixed in [this update ](http://www.aspose.com/community/files/51/.net-components/aspose.network-for-.net/entry271668.aspx).