How do I resolve a OpenPop.Net Authenticate Exception
I am using OpenPop.Net to开发者_开发知识库 connect to a GoDaddy hosted email account in a C# application. The Authenticate() method throws an exception with the error message of "The stream used to retrieve responses from was closed". I doubled checked that the POPServer, POPPort, POPUserName, and POPPassword values were valid using Outlook 2007.
using (Pop3Client pop3 = new Pop3Client())
{
pop3.Connect(POPServer, POPPort, false);
pop3.Authenticate(POPUserName, POPPassword);
Int32 messageCount = pop3.GetMessageCount();
}
The Authenticate() method supports a 3rd parameter, an enumeration called AuthenticationMethod. According to the help file, if the 3rd parameter is not passed the Authenticate() method defaults to an authentication method of Auto. The help file goes on to say that the Auto method is the recommended method to authenticate with. If Apop is supported by the server, Apop is used for authentication. If Apop is not supported, Auto will fall back to UsernameAndPassword authentication.
I tried explicitly passing Auto, and the Authenticate() method failed with the same error. I then tried explicitly passing UsernameAndPassword, this time it worked. I'm not sure if this is a bug in OpenPop.Net or a problem with the POP server. Here is the working code.
using (Pop3Client pop3 = new Pop3Client())
{
pop3.Connect(POPServer, POPPort, false);
pop3.Authenticate(POPUserName, POPPassword, AuthenticationMethod.UsernameAndPassword);
Int32 messageCount = pop3.GetMessageCount();
}
精彩评论