{"id":1675,"date":"2011-01-17T15:04:32","date_gmt":"2011-01-17T13:04:32","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1675"},"modified":"2014-04-15T14:10:53","modified_gmt":"2014-04-15T12:10:53","slug":"received-unexpected-eof-0-bytes-from-transport-stream","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/received-unexpected-eof-0-bytes-from-transport-stream","title":{"rendered":"Received an unexpected EOF or 0 bytes from the transport stream"},"content":{"rendered":"<p>When you are getting the following error:<br \/>\n<strong>Received an unexpected EOF or 0 bytes from the transport stream.<\/strong><br \/>\nwhile using <em>ConnectSSL<\/em> method, most likely your server incorrectly advertises TLS support. You might be required to use SSLv2 or SSLv3.<\/p>\n<p>This article describes <strong>how to force SSLv3 or SSLv2 in Mail.dll<\/strong> or in regular .NET SslStream class.<\/p>\n<h2>Force SSLv3 or SSLv2 in Mail.dll<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\nusing (Imap client = new Imap())\r\n{\r\n   \/\/ Force to use SSL3\r\n   client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Ssl3;\r\n   \/\/ Ignore certificate errors\r\n   client.ServerCertificateValidate += (sender, e) =&gt; { e.IsValid = true; };\r\n   client.ConnectSSL(&quot;imap.gmail.com&quot;);\r\n   client.Login(&quot;user@gmail.com&quot;, &quot;password&quot;);\r\n\r\n   client.SelectInbox();\r\n   foreach(long uid in client.Search(Flag.Unseen))\r\n   {\r\n       var eml = client.GetMessageByUID(uid);\r\n       IMail email = new MailBuilder().CreateFromEml(eml);\r\n       Console.WriteLine(email.Subject);\r\n   }\r\n   client.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nUsing client As New Imap()\r\n\t' Force to use SSL3\r\n\tclient.SSLConfiguration.EnabledSslProtocols = SslProtocols.Ssl3\r\n\t' Ignore certificate errors\r\n\tAddHandler client.ServerCertificateValidate, AddressOf Validate\r\n\tclient.ConnectSSL(&quot;imap.gmail.com&quot;)\r\n\tclient.Login(&quot;user@gmail.com&quot;, &quot;password&quot;)\r\n\r\n\tclient.SelectInbox()\r\n\tFor Each uid As Long In client.Search(Flag.Unseen)\r\n\t\tDim eml = client.GetMessageByUID(uid)\r\n\t\tDim email As IMail = New MailBuilder().CreateFromEml(eml)\r\n\t\tConsole.WriteLine(email.Subject)\r\n\tNext\r\n\tclient.Close()\r\nEnd Using\r\n\r\nPrivate Sub ValidateCerificate( _\r\n    ByVal sender As Object, _\r\n    ByVal e As ServerCertificateValidateEventArgs)\r\n\r\n    Const ignoredErrors As SslPolicyErrors = _\r\n        SslPolicyErrors.RemoteCertificateChainErrors Or _\r\n        SslPolicyErrors.RemoteCertificateNameMismatch\r\n\r\n    If (e.SslPolicyErrors And Not ignoredErrors) = SslPolicyErrors.None Then\r\n        e.IsValid = True\r\n        Return\r\n    End If\r\n    e.IsValid = False\r\nEnd Sub\r\n\r\n<\/pre>\n<h2>Force SSLv3 or SSLv2 in SslStream class<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\nconst string host = &quot;imap.gmail.com&quot;;\r\n\r\nSocket socket = new Socket(\r\n   AddressFamily.InterNetwork,\r\n   SocketType.Stream,\r\n   ProtocolType.Tcp);\r\nsocket.Connect(host, 993);\r\nusing(SslStream ssl = new SslStream(new NetworkStream(socket), true))\r\n{\r\n   ssl.AuthenticateAsClient(\r\n      host,\r\n      new X509CertificateCollection(),\r\n      SslProtocols.Ssl3,\r\n      true);\r\n   using(StreamReader reader = new StreamReader(ssl))\r\n   {\r\n       Console.WriteLine(reader.ReadLine());\r\n   }\r\n}\r\nsocket.Close();\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nConst host As String = &quot;imap.gmail.com&quot;\r\n\r\nDim socket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)\r\nsocket.Connect(host, 993)\r\nUsing ssl As New SslStream(New NetworkStream(socket), True)\r\n\tssl.AuthenticateAsClient(host, New X509CertificateCollection(), SslProtocols.Ssl3, True)\r\n\tUsing reader As New StreamReader(ssl)\r\n\t\tConsole.WriteLine(reader.ReadLine())\r\n\tEnd Using\r\nEnd Using\r\nsocket.Close()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When you are getting the following error: Received an unexpected EOF or 0 bytes from the transport stream. while using ConnectSSL method, most likely your server incorrectly advertises TLS support. You might be required to use SSLv2 or SSLv3. This article describes how to force SSLv3 or SSLv2 in Mail.dll or in regular .NET SslStream [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[53],"class_list":["post-1675","post","type-post","status-publish","format-standard","hentry","category-mail-dll","category-programming","tag-ssl"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1675"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=1675"}],"version-history":[{"count":5,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1675\/revisions"}],"predecessor-version":[{"id":4339,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1675\/revisions\/4339"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}