0

I am trying to connect to an Exchange server using IMAP from my .NET 4.0 application. Below is the code I have problem with:

var host = "mail.mydomain.com";
var port = 993;
var tcpClient = new TcpClient(host, port);
var stream = new SslStream(tcpClient.GetStream(), false, (sender, cert, chain, e) => true, null);
stream.AuthenticateAsClient(host); // => IOException here

I get Authentication failed because remote party has closed the transport stream on the last line.
I have already tried to use the below workarounds with no luck:

  • ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;  
    
  • Changed target framework to .NET 4.5 and tried:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    
  • Added SchUseStrongCrypto registry key in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319and rebooted.

However, if I change target framework of my program to .NET 2.0, same code works with no problem. My program is hosted on a Windows Server 2008 R2.

Kamyar
  • 18,639
  • 9
  • 97
  • 171
  • Did you find any solution for this? I'm having the same issues. I have made the changes described above. Working on localhost but error on Windows Server 2012R2, IIS 8.5 – ozimax06 Mar 05 '18 at 19:40
  • @ozimax06 Instead of built-in libraries, I used [MailKit](https://github.com/jstedfast/MailKit) and it worked with no problem – Kamyar Mar 06 '18 at 06:56

0 Answers0