refactor: support all TLS/SSL versions

This commit is contained in:
Oliver Booth 2024-10-23 22:29:05 +01:00
parent 43bcc87ad0
commit 9dd35b7ff0
Signed by: oliverbooth
GPG Key ID: 2A862C3F46178E8E

View File

@ -1,4 +1,5 @@
using System.Net.Mail; using System.Net.Mail;
using System.Security.Authentication;
using MailKit.Security; using MailKit.Security;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
@ -95,6 +96,7 @@ public class ContactController : Controller
destination = mailSection.GetSection("Destination").Value ?? string.Empty; destination = mailSection.GetSection("Destination").Value ?? string.Empty;
var client = new SmtpClient(); var client = new SmtpClient();
client.SslProtocols = SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13;
client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect(mailServer, port, SecureSocketOptions.SslOnConnect); client.Connect(mailServer, port, SecureSocketOptions.SslOnConnect);
client.Authenticate(mailUsername, mailPassword); client.Authenticate(mailUsername, mailPassword);