Hi,
Since Microsoft started disabling some legacy TLS 1.0 and 1.1 requests my emails sent from unity have been failing more and more. This is expected as they are being disabled as mentioned here: New opt-in endpoint available for SMTP AUTH clients still needing legacy TLS - Microsoft Community Hub however I believe my code should be sending as version 1.2, which it is seemingly not.
I get this error: System.Net.Mail.SmtpException: 421 4.7.66 TLS 1.0 and 1.1 are not supported. Please upgrade/update your client to support TLS 1.2. Visit Bing
I have tried modifying my code to resolve this. Sometimes it appears fixed, other times it does not. It’s hard to know for sure when a change has had an impact, or if this is just one of the times MS allows legacy requests through.
As far as I can tell my code should be being sent using TLS 1.2, but I still get errors, and the fact it’s happening more regularly is becoming a problem.
I’ve tried many suggestions from ( Unity 2017.1 - TLS 1.2 still not working with .NET 4.6 ), including toggling code stripping levels, .NET versions, etc, but still I get the error:
I am currently using Unity LTS 2020.3.21, testing in the editor, with the iOS platform.
My current code is as follows, but I’ve tried many variations.
SmtpClient smtpServer = new SmtpClient("smtp-mail.outlook.com");
smtpServer.Port = 587;
smtpServer.EnableSsl = true;
smtpServer.UseDefaultCredentials = false;
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpServer.Credentials = new System.Net.NetworkCredential("secretusername ", "secret password") as ICredentialsByHost;
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
smtpServer.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
smtpServer.SendAsync(mail, toEmail);
If anyone has suggestions on how to ensure TLS 1.2 is used, or whether the error message is obscuring another issue, I would love to know.
Thanks!