首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于意外的数据包格式登录到Pop3,握手失败

由于意外的数据包格式登录到Pop3,握手失败
EN

Stack Overflow用户
提问于 2016-03-09 02:22:46
回答 1查看 20.4K关注 0票数 4

我正在尝试更新监视Exchange Server邮箱的代码,以便它可以使用SSL登录。然而,当它尝试登录时,我得到了错误:The handshake failed due to an unexpected packet format.

我的连接代码如下(删除了日志和注释):

代码语言:javascript
复制
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;

try
{
    tcpClient = new TcpClient(Host, Port);
}
catch (SocketException e) { ... }

try
{
    var stream = client.GetStream();
    ssl = new SslStream(stream);
    ssl.AuthenticateAsClient(Host, null, SslProtocols.Tls, true);
    streamReader = new StreamReader(ssl);

    response = streamReader.ReadLine();
    if (response.StartsWith("+OK"))
    {
        response = SendReceive("USER ", UserName.Trim() + "@" + Domain.Trim());
        if (response.StartsWith("+OK"))
        {
            response = SendReceive("PASS ", Password);
        }
    }

    if (response.StartsWith("+OK"))
        result = true;
}
catch (Exception e) { ... }

从日志记录中,我已经在第二次尝试后的前4行中的某处找到了异常(实际上是在GetStreamReader方法中,但为了简洁和可读性我将其组合在一起)。

我收到的异常如下:

代码语言:javascript
复制
    --- Exception ---
Error:  3/8/2016 10:32:35 AM    The handshake failed due to an unexpected packet format.
Info:   3/8/2016 10:32:35 AM    There was an error connecting to the account.
The server returned 
The handshake failed due to an unexpected packet format.
Info:   3/8/2016 10:32:35 AM    Source: System
Info:   3/8/2016 10:32:35 AM    Method: Void StartReadFrame(Byte[], Int32, System.Net.AsyncProtocolRequest)
Info:   3/8/2016 10:32:35 AM    
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
   at POP3_Communication.Pop3.GetStreamReader(TcpClient client)
   at POP3_Communication.Pop3.Connect()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-09 05:04:22

我可以根据你的异常堆栈跟踪进一步缩小范围:)

at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost,X509CertificateCollection clientCertificates,SslProtocols enabledSslProtocols,Boolean checkCertificateRevocation)

问题是您连接到的端口没有启用SSL (即您可能连接到端口110而不是995)。

您是否考虑过使用诸如MailKit之类的库,而不是使用自己的解决方案?

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35875039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档