SslStream.AuthenticateAsClient()验证失败
如下是我做的一个读取邮件内容的一段程序,下面是我连接邮箱服务器的一段代码
我连接邮箱服务器serverTcpConnection = new TcpClient(popServer, port);
连接已成功,但我在 ((SslStream)pop3Stream).AuthenticateAsClient(popServer);
验证时一直提示 System.IO.IOException: 由于意外的数据包格式,握手失败。
if (pop3ConnectionState != Pop3ConnectionStateEnum.Disconnected &&
pop3ConnectionState != Pop3ConnectionStateEnum.Closed &&
!isTimeoutReconnect)
{
CallWarning("connect", "", "Connect command received, but connection state is: " + pop3ConnectionState.ToString());
}
else
{
//establish TCP connection
try
{
CallTrace(" Connect at port {0}", port);
serverTcpConnection = new TcpClient(popServer, port);
}
catch (Exception ex)
{
throw new Pop3Exception("Connection to server " + popServer + ", port " + port + " failed.\nRuntime Error: " + ex.ToString());
}
if (useSSL)
{
//get SSL stream
try
{
CallTrace(" Get SSL connection");
pop3Stream = new SslStream(serverTcpConnection.GetStream(), false);
pop3Stream.ReadTimeout = readTimeout;
}
catch (Exception ex)
{
throw new Pop3Exception("Server " + popServer + " found, but cannot get SSL data stream.\nRuntime Error: " + ex.ToString());
}
//perform SSL authentication
try
{
CallTrace(" Get SSL authentication");
((SslStream)pop3Stream).AuthenticateAsClient(popServer);
}
catch (Exception ex)
{
throw new Pop3Exception("Server " + popServer + " found, but problem with SSL Authentication.\nRuntime Error: " + ex.ToString());
}