I support a legacy on-premise .Net 4.0 WinForms application. The application uses System.Net.Mail.SmtpClient
to send emails via our customers' own SMTP servers. Recently, we've had issues with Office 365 mandating TLS 1.2. Having read that as long as .Net 4.5 is installed, .Net 4.0 applications can utilise TLS 1.2, I added this line:
System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // 3072 = TLS 1.2
This solved the issue of connecting to Office 365, but introduced issues making non-SMTP connections to other older 3rd party applications that do not support TLS 1.2. I therefore changed the approach to add TLS 1.2 to the list of allowable protocols rather than set it as the mandated protocol (as outlined in this question and this question), and also added TLS 1.3 at the same time:
System.Net.ServicePointManager.SecurityProtocol |=
(SecurityProtocolType)3072 | // 3072 = TLS 1.2
(SecurityProtocolType)12288; // 12288 = TLS 1.3
This resolved both issues for some clients and works in our test environment with our own Office 365 account. However, some of our clients have reported issues connecting to Office 365 again. Revert to mandating TLS 1.2 again resolves the SMTP issue, but reintroduced the other problem.
Is it possible to specify the security protocol for a specific connection rather than take this global approach?