如何解决 OpenPop.Net 身份验证异常
我正在使用 OpenPop.Net 连接到 C# 应用程序中的 GoDaddy 托管电子邮件帐户。 Authenticate() 方法引发异常,并显示错误消息“用于检索响应的流已关闭”。我使用 Outlook 2007 仔细检查了 POPServer、POPPort、POPUserName 和 POPPassword 值是否有效。
using (Pop3Client pop3 = new Pop3Client())
{
pop3.Connect(POPServer, POPPort, false);
pop3.Authenticate(POPUserName, POPPassword);
Int32 messageCount = pop3.GetMessageCount();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Authenticate() 方法支持第三个参数,一个名为 AuthenticationMethod 的枚举。根据帮助文件,如果不传递第3个参数,Authenticate()方法默认为Auto认证方式。帮助文件继续指出,自动方法是推荐的身份验证方法。如果服务器支持Apop,则使用Apop进行认证。如果不支持 Apop,Auto 将回退到 UsernameAndPassword 身份验证。
我尝试显式传递 Auto,但 Authenticate() 方法失败并出现相同的错误。然后我尝试显式传递用户名和密码,这次成功了。我不确定这是 OpenPop.Net 中的错误还是 POP 服务器的问题。这是工作代码。
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.