Home > OS >  An error occurred while attempting to establish an SSL or TLS connection
An error occurred while attempting to establish an SSL or TLS connection

Time:08-01

i'm trying to make a simple email viewer , but this SSL error is distracting me to continue , some emails works fine and some i get this error , like i have two yahoo emails , one account works , the other doesn't work ! it's the same imap what's the issue ?

my code :

 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

it's simple i guess.

my errors :

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)

why it spams this errors without logining to the account ? and the account keeps retrying for ever , even with rotating proxies !

i added C# since i can translate to vb.net

CodePudding user response:

Check your web.config --> httpruntime --> framework version, if it is less than 4.7 it does not support tls1.2 which might be the issue.

CodePudding user response:

Try to add this TLS code before call ImapClient.

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