繁体   English   中英

尝试建立 SSL 或 TLS 连接时出错

[英]An error occurred while attempting to establish an SSL or TLS connection

我正在尝试制作一个简单的 email 查看器,但是这个 SSL 错误让我分心,有些电子邮件工作正常,有些我收到此错误,就像我有两封雅虎电子邮件,一个帐户有效,另一个无效? 它是相同的 imap 有什么问题?

我的代码:

 Using client = New ImapClient()


                client.CheckCertificateRevocation = False

                client.Connect(imp, 993, SecureSocketOptions.Auto)

                client.Authenticate(login, pass)
                Dim inbox = client.Inbox
                inbox.Open(FolderAccess.[ReadOnly])

                Dim query = SearchQuery.DeliveredAfter(DateTime.Parse("2018-01-01"))


Dim uids = inbox.Search(query)
If uids.Count > 0 Then
'some code here
End If

client.Disconnect(True)


Catch ex As Exception
If (ex.Message.Contains("authentication failed") OrElse ex.Message.Contains("Invalid") OrElse ex.Message.Contains("Authentication") OrElse ex.Message.Contains("login failed")) Then
            
             MsgBox("wrong pass")


        ElseIf (ex.Message.Contains("Failed to connect") OrElse ex.Message.Contains("host") OrElse ex.Message.Contains(" Bad Request") OrElse ex.Message.Contains("connnection") OrElse ex.Message.Contains("ssl")) Then
             MsgBox("attempting a retry. " &  ex.Message)
           'my thread retry code
        Else
            MsgBox("unexpected error : " &  ex.Message)

        End If


End Try

我猜这很简单。

我的错误:

An error occurred while attempting to establish an SSL or TLS connection.

The server's SSL certificate could not be validated for the following reasons:
• The root certificate has the following errors:
  • A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.



The operation has timed out.
See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#SslHandshakeException for possible solutions.

   at MailKit.Net.Imap.ImapClient.<ConnectAsync>d__108.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MailKit.Net.Imap.ImapClient.Connect(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)
   at email.Form1.Checker(String login, String pass, String imp, String PrxIP, Int32 PrxPrt, String PrxLogin, String PrxPass)

为什么它在不登录帐户的情况下发送此错误? 即使使用轮换代理,该帐户也会永远重试!

我添加了 C# 因为我可以翻译成 vb.net

检查您的 web.config --> httpruntime --> 框架版本,如果它低于 4.7,则它不支持 tls1.2,这可能是问题所在。

尝试在调用 ImapClient 之前添加此 TLS 代码。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM