diff --git a/Directory.Packages.props b/Directory.Packages.props index 8717ba7..44e5aa1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -32,7 +32,6 @@ - diff --git a/HrynCo.NotificationService.Web/Controllers/Admin/AdminChannelsController.cs b/HrynCo.NotificationService.Web/Controllers/Admin/AdminChannelsController.cs index d05585d..69333f8 100644 --- a/HrynCo.NotificationService.Web/Controllers/Admin/AdminChannelsController.cs +++ b/HrynCo.NotificationService.Web/Controllers/Admin/AdminChannelsController.cs @@ -5,11 +5,10 @@ using HrynCo.NotificationService.Services.EmailChannels.Get; using HrynCo.NotificationService.Services.EmailChannels.GetAll; using HrynCo.NotificationService.Services.EmailChannels.Update; using HrynCo.NotificationService.Web.Controllers.Admin.ViewModels; -using MailKit.Net.Smtp; -using MailKit.Security; using MediatR; using Microsoft.AspNetCore.Mvc; -using MimeKit; +using System.Net; +using System.Net.Mail; namespace HrynCo.NotificationService.Web.Controllers.Admin; @@ -153,28 +152,24 @@ public class AdminChannelsController : Controller try { - var message = new MimeMessage(); - message.From.Add(new MailboxAddress(smtp.FromName, smtp.FromEmail)); - message.To.Add(MailboxAddress.Parse(request.ToEmail)); - message.Subject = "✅ Test email from Notification Service"; - message.Body = new TextPart("plain") + using var client = new SmtpClient(smtp.Host, smtp.Port) { - Text = $"This is a test email sent from the Notification Service admin panel.\n\nChannel: {result.Result.ServiceName}\nHost: {smtp.Host}:{smtp.Port}" + EnableSsl = smtp.UseSsl, + Credentials = string.IsNullOrWhiteSpace(smtp.Username) + ? null + : new NetworkCredential(smtp.Username, smtp.Password) }; - using var client = new SmtpClient(); - var secureSocket = smtp.Port == 465 - ? SecureSocketOptions.SslOnConnect - : smtp.UseSsl - ? SecureSocketOptions.StartTls - : SecureSocketOptions.None; - await client.ConnectAsync(smtp.Host, smtp.Port, secureSocket, ct); + var message = new MailMessage + { + From = new MailAddress(smtp.FromEmail, smtp.FromName), + Subject = "✅ Test email from Notification Service", + Body = $"This is a test email sent from the Notification Service admin panel.\n\nChannel: {result.Result.ServiceName}\nHost: {smtp.Host}:{smtp.Port}", + IsBodyHtml = false + }; + message.To.Add(request.ToEmail); - if (!string.IsNullOrWhiteSpace(smtp.Username)) - await client.AuthenticateAsync(smtp.Username, smtp.Password, ct); - - await client.SendAsync(message, ct); - await client.DisconnectAsync(true, ct); + await client.SendMailAsync(message, ct); return Ok(new { success = true, message = $"Test email sent to {request.ToEmail}." }); } diff --git a/HrynCo.NotificationService.Web/HrynCo.NotificationService.Web.csproj b/HrynCo.NotificationService.Web/HrynCo.NotificationService.Web.csproj index d781c6f..b96102a 100644 --- a/HrynCo.NotificationService.Web/HrynCo.NotificationService.Web.csproj +++ b/HrynCo.NotificationService.Web/HrynCo.NotificationService.Web.csproj @@ -8,7 +8,6 @@ -