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 inHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319
and 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.