using MailKit.Net.Smtp; using MimeKit; namespace Infrastructure.Email { public class EmailSender : IEmailSender { 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(new MailboxAddress(to)); message.Subject = subject; message.Body = new TextPart("html") { Text = body }; using (var client = new SmtpClient()) { client.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); } } } }