Verifying Login Credentials with Pop3Client

In attempting to log in to a POP3 server, does the Aspose.Network.Pop3Client class give us any way to test the credentials before just trying to use them?

I’ve seen two methods, Pop3Client.Connect(true), and Pop3Client.Login(), but both of these don’t return anything or even throw an exception if the credentials fail. Ideally, Pop3Client.Login would return a boolean indicating whether or not the login attempt succeeded (and maybe Pop3Client.Connect(true) would throw an exception). Currently, I have to try another function (e.g. Pop3Client.GetMessageCount()) which will throw an exception since I haven’t actually logged into the POP3 server.

Hi,

The Pop3Client.Connect(true) throws exception in case username and password are not validated. I tried to connect to Gmail pop3 with incorrect authentication information and got the following exception thrown at the Connect(true) method:

"Login error-ERR [AUTH] Username and password not accepted."

Could you please tell which version of Aspose.Network you are using and the email server server you are connecting to?

It appears that this only occurs when submitting a blank username and password. My mistake for not troubleshooting more. I still find that strange that it doesn’t try the login, even if you set the login flag to true, or at least throw an exception on the invalid username.

I noticed that for a username/blank password combination that Pop3Client.Connect(true) throws a NullReferenceException. And with a blank username (but a non-blank password), the Pop3Client.Login() method throws a NullReferenceException.

With POP3, these commands go:

USER notblank
+OK
PASS
-ERR Logon failure: unknown user name or bad password.
USER
-ERR Protocol error. 16
PASS notblank
-ERR Command is not valid in this state.

Hi,

I am sorry I could not reproduce the problem at my end. Could you please share your sample code and environment (OS, .NET framework and Aspose.Network dll version) for our testing? I tried the code below with Aspose.Network for .NET v5.2 and it worked (also with other values mentioned in the comments).

string host = “[ftp.microsoft.com](http://ftp.microsoft.com/)”;
string username = null; // other values: “anonymous”, ""
string password = null; // other values: “”, “any password”

FtpClient client = null;
try
{
Console.WriteLine(“Connecting to FTP server…”);
client = new FtpClient(host, 21, username, password);
client.Connect(true);
Console.WriteLine("Current dir: " + client.GetCurrentDirectory());
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
client.Disconnect();
Console.WriteLine(“Disconnected.”);
}

I am using Windows XP, .NET 3.5, Aspose 5.2.

The following code does not throw an exception at the “client.Connect(true);” line, but I would expect it to throw a Pop3Exception.

using (var client = new Pop3Client(“[pop.gmail.com](http://pop.gmail.com/)”, “”, “”))
{
client.Port = 995;
client.SecurityMode = Pop3SslSecurityMode.Implicit;
client.EnableSsl = true;

try
{
client.Connect(true);
System.Console.WriteLine(“Connection succeeded”);
}
catch (Exception ex)
{
System.Console.WriteLine("Exception: " + ex);
}
}

Hi,

Thanks for posting the sample code. We have got the idea and have reproduced the issue at our end. I have logged it in our bug tracking system (ID: 16812). We will notify you when it gets resolved. Sorry for the inconvenience.

The issues you have found earlier (filed as 16812) have been fixed in [this update ](http://www.aspose.com/community/files/51/.net-components/aspose.network-for-.net/entry240102.aspx).

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