带有IIS SSL证书的OpenPOP.POP3
问题描述:
我正在使用OpenPOP 我试图从办公室交换服务器检索邮件。这是我的代码带有IIS SSL证书的OpenPOP.POP3
popClient.Connect(host.Host, (int)host.Port, (bool)host.Ssl);
popClient.Authenticate(host.Username, host.Password);
Prodlem是SSL证书在IIS 7中创建和心不是一个有效的证书有什么办法我绕过这一点。
它给我的错误远程证书是无效的根据验证程序。
答
是的,有一种方法。它需要一些小的代码更改是POPClient类。
步骤1:将用于验证服务器的SslStream实例的构造函数替换为允许您提供验证远程方提供的证书的委托。因此更换
SslStream stream = new SslStream(clientSocket.GetStream(), false);
从的popclient类,连接方法与
SslStream stream = new SslStream(clientSocket.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
步骤2:提供一个由委托调用的方法和通过返回总是如此迫使远程证书的验证:
public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true; // force the validation of any certificate
}
有关该主题的更多详细信息,请检查文档msdn。
感谢您的快速解决,指出我在正确的方向。 OpenPOP现在有一个支持这个的重载。 – JTew 2011-09-05 03:47:53