Connect to Office 365 using TLS1.2 from C#

Microsoft Office 365 will no more support to connect using TLS1.0 and TLS1.1, please read it here.

All the browser-server or client-server applications must use TLS1.2 or later to be able communicate with Office 365 services.

Here is how we can implement it in C# to connect using TLS1.2, put the following line of code either in the constructor of the class which you are using to communicate with the Office 365 services or in the method directly:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;          

As more and more service providers like PayPal and others or switching to support TLS1.2 only, you can put above line of code before calling any web service or API which supports TLS1.2 only.

If your service provider supports more than one security protocol you can mention it like below:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

If you are using .NET Framework version older than 4.5 then use the following code:

System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
Comments
Share it