using MailKit.Net.Smtp; using MimeKit; namespace Infrastructure.Email { public class EmailSender : IEmailSender { [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5359:请勿禁用证书验证", Justification = "<挂起>")] public void SendMail(string name, string from, string to, string subject, string body, string host, int port, string userName, string password) { var message = new MimeMessage(); message.From.Add(new MailboxAddress(name, from)); message.To.Add(MailboxAddress.Parse(to)); message.Subject = subject; message.Body = new TextPart("html") { Text = body }; using var client = new SmtpClient { ServerCertificateValidationCallback = (s, c, h, e) => true }; client.Connect(host, port, false); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(userName, password); client.Send(message); client.Disconnect(true); } } }