Connect then Login doesn't enter proper State in POP3/IMAP

I am trying to separate my Connect/Login calls using both the Pop3Client and ImapClient classes to help make my error reporting more specific.

In passing bad username/password data, calling “client.Connect(true);” will throw a Pop3Exception/ImapException.

But, breaking the connection and login into two separate calls, I do not receive the Exception, and I instead get an error later in my code:

using (var client = new Pop3Client(“[pop.gmail.com](http://pop.gmail.com/)”, 995, “baduser”, “badpw”))
// using (var client = new ImapClient(“[imap.gmail.com](http://imap.gmail.com/)”, 993, “baduser”, “badpw”))
{
client.SecurityMode = Pop3SslSecurityMode.Implicit; // or ImapSslSecurityMode.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;
}

// 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.

Hi,


Thank you for inquiry.

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
  1. exception is thrown on Connect(false) for IMAP
  2. 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.
saqib.razzaq:
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
  1. exception is thrown on Connect(false) for IMAP
  2. 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.
jay_bp:

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.
Yes, the IMAP throws exception on Connect(false) method, when a bad user/pwd is specified.

jay_bp:

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
  1. Calls Connect(false)
  2. Sets user and password
  3. Calls Login()
All 3 steps worked fine at my end with correct user/pwd, without any exception.

I have also attached a screenshot of my debug session in VS.
saqib.razzaq:
jay_bp:

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
  1. Calls Connect(false)
  2. Sets user and password
  3. 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

Hi,


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).

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Thanks for the updates.

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

Hi,


Thanks for posting the details. We will check this issue and will inform you when it will be resolved. The Issue ID is 21264.

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).

This message was posted using Notification2Forum from Downloads module by aspose.notifier.