From a65e926a5331cc3ee537853a1006b8b7db688d30 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Sat, 16 May 2026 00:28:31 +0200 Subject: [PATCH] Fixed email sending logic --- .../NotificationsFeatureTests.cs | 11 +++++++++++ LiteCharms.Features/Email/EmailService.cs | 5 +++-- .../ProcessEmailNotificationsEventHandler.cs | 16 +++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/LiteCharms.Features.Tests/NotificationsFeatureTests.cs b/LiteCharms.Features.Tests/NotificationsFeatureTests.cs index ede7fd8..2c7518b 100644 --- a/LiteCharms.Features.Tests/NotificationsFeatureTests.cs +++ b/LiteCharms.Features.Tests/NotificationsFeatureTests.cs @@ -1,4 +1,5 @@ using LiteCharms.Features.Shop.Notifications; +using LiteCharms.Features.Shop.Notifications.Events; namespace LiteCharms.Features.Tests; @@ -32,4 +33,14 @@ public class NotificationsFeatureTests(CommonFixture fixture, ITestOutputHelper foreach (var error in createResult.Errors) output.WriteLine(error.Message); } + + [Fact] + public async Task ProcessEmailNotificationsEvent_ShouldSucceed() + { + var notification = ProcessEmailNotificationsEvent.Create(); + + await fixture.Mediator.Publish(notification); + + Assert.True(true); + } } diff --git a/LiteCharms.Features/Email/EmailService.cs b/LiteCharms.Features/Email/EmailService.cs index 3e6c103..72c5665 100644 --- a/LiteCharms.Features/Email/EmailService.cs +++ b/LiteCharms.Features/Email/EmailService.cs @@ -35,8 +35,9 @@ public class EmailService(IOptions options) : IDisposable var bodyBuilder = new BodyBuilder(); - foreach (var attachment in message.Body?.Attachments!) - bodyBuilder.Attachments.Add(attachment.Name!, attachment.FileStream!, cancellationToken); + if (message.Body!.Properties.HasAttachments) + foreach (var attachment in message.Body?.Attachments!) + bodyBuilder.Attachments.Add(attachment.Name!, attachment.FileStream!, cancellationToken); if (!message.Body.Properties.IsHtml) bodyBuilder.TextBody = message.Body.Message; if (message.Body.Properties.IsHtml) bodyBuilder.HtmlBody = message.Body.Message; diff --git a/LiteCharms.Features/Shop/Notifications/Events/Handlers/ProcessEmailNotificationsEventHandler.cs b/LiteCharms.Features/Shop/Notifications/Events/Handlers/ProcessEmailNotificationsEventHandler.cs index f12242b..6917777 100644 --- a/LiteCharms.Features/Shop/Notifications/Events/Handlers/ProcessEmailNotificationsEventHandler.cs +++ b/LiteCharms.Features/Shop/Notifications/Events/Handlers/ProcessEmailNotificationsEventHandler.cs @@ -1,4 +1,5 @@ -using LiteCharms.Features.Email; +using k8s.KubeConfigModels; +using LiteCharms.Features.Email; using LiteCharms.Features.Shop.Notifications.Models; using LiteCharms.Features.Shop.Postgres; @@ -13,15 +14,16 @@ public class ProcessEmailNotificationsEventHandler(IDbContextFactory o.CreatedAt) .ThenBy(o => o.Priority) - .Where(n => n.CorrelationIdType == CorrelationIdTypes.Email) - .Where(n => n.Direction == NotificationDirection.Outgoing) + .Where(n => n.Platform == NotificationPlatforms.Email && + n.Direction == NotificationDirection.Outgoing && n.Processed == false) .Take(message.MaxRecords) .ToListAsync(cancellationToken); @@ -48,7 +50,7 @@ public class ProcessEmailNotificationsEventHandler(IDbContextFactory