From 33112dcf79f09be1719b3d3fb5e77a3e9042477c Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Mon, 4 May 2026 23:29:29 +0200 Subject: [PATCH] Stable email sender --- LiteCharms.Extensions/LiteCharms.Extensions.csproj | 2 +- LiteCharms.Extensions/Services.cs | 2 +- LiteCharms.Features/LiteCharms.Features.csproj | 2 +- .../Commands/Handlers/SendEmailCommandHandler.cs | 2 +- .../Utilities/Commands/SendEmailCommand.cs | 8 ++++---- LiteCharms.Models/LiteCharms.Models.csproj | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/LiteCharms.Extensions/LiteCharms.Extensions.csproj b/LiteCharms.Extensions/LiteCharms.Extensions.csproj index ae87df1..2e18e32 100644 --- a/LiteCharms.Extensions/LiteCharms.Extensions.csproj +++ b/LiteCharms.Extensions/LiteCharms.Extensions.csproj @@ -11,7 +11,7 @@ LiteCharms.Extensions - 1.0.7 + 1.0.8 Khwezi Mngoma Lite Charms (PTY) Ltd Extension components for Lite Charms applications. diff --git a/LiteCharms.Extensions/Services.cs b/LiteCharms.Extensions/Services.cs index 44959ec..61c9dad 100644 --- a/LiteCharms.Extensions/Services.cs +++ b/LiteCharms.Extensions/Services.cs @@ -6,7 +6,7 @@ namespace LiteCharms.Extensions; public static class Services { - public static IServiceCollection AddEmail(this IServiceCollection services, IConfiguration configuration) + public static IServiceCollection AddEmailServices(this IServiceCollection services, IConfiguration configuration) { services.Configure(configuration.GetSection("Email")); diff --git a/LiteCharms.Features/LiteCharms.Features.csproj b/LiteCharms.Features/LiteCharms.Features.csproj index b248d24..97e26cb 100644 --- a/LiteCharms.Features/LiteCharms.Features.csproj +++ b/LiteCharms.Features/LiteCharms.Features.csproj @@ -11,7 +11,7 @@ LiteCharms.Features - 1.0.12 + 1.0.14 Khwezi Mngoma Lite Charms (PTY) Ltd Feature components for Lite Charms applications. diff --git a/LiteCharms.Features/Utilities/Commands/Handlers/SendEmailCommandHandler.cs b/LiteCharms.Features/Utilities/Commands/Handlers/SendEmailCommandHandler.cs index 0300585..e3fcdf7 100644 --- a/LiteCharms.Features/Utilities/Commands/Handlers/SendEmailCommandHandler.cs +++ b/LiteCharms.Features/Utilities/Commands/Handlers/SendEmailCommandHandler.cs @@ -16,7 +16,7 @@ public class SendEmailCommandHandler(IOptions smtpOptions) : IRequ if(settings.Credentials == null) return Result.Fail(new Error("SMTP credentials are not configured.")); - if(string.IsNullOrWhiteSpace(settings.Credentials.Username) || string.IsNullOrWhiteSpace(settings.Credentials.Password)) + if(string.IsNullOrWhiteSpace(settings?.Credentials.Username) || string.IsNullOrWhiteSpace(settings.Credentials.Password)) return Result.Fail(new Error("SMTP credentials are incomplete.")); if(string.IsNullOrWhiteSpace(settings.Host) || settings.Port == 0) diff --git a/LiteCharms.Features/Utilities/Commands/SendEmailCommand.cs b/LiteCharms.Features/Utilities/Commands/SendEmailCommand.cs index 64d53e5..8b44f01 100644 --- a/LiteCharms.Features/Utilities/Commands/SendEmailCommand.cs +++ b/LiteCharms.Features/Utilities/Commands/SendEmailCommand.cs @@ -41,7 +41,7 @@ public class SendEmailCommand : IRequest if (string.IsNullOrWhiteSpace(senderName)) throw new ArgumentException("Sender name cannot be null or empty.", nameof(senderName)); - if (!string.IsNullOrWhiteSpace(senderName) && senderName.Length > 255) + if (!string.IsNullOrWhiteSpace(senderName) && senderName?.Length > 255) throw new ArgumentException("Sender name cannot exceed 255 characters.", nameof(senderName)); if (string.IsNullOrWhiteSpace(to)) @@ -50,13 +50,13 @@ public class SendEmailCommand : IRequest if (string.IsNullOrWhiteSpace(recipientName)) throw new ArgumentException("Recipient name cannot be null or empty.", nameof(recipientName)); - if (!string.IsNullOrWhiteSpace(recipientName) && recipientName.Length > 255) + if (!string.IsNullOrWhiteSpace(recipientName) && recipientName?.Length > 255) throw new ArgumentException("Recipient name cannot exceed 255 characters.", nameof(recipientName)); if (string.IsNullOrWhiteSpace(subject)) throw new ArgumentException("Subject cannot be null or empty.", nameof(subject)); - if (subject.Length > 2048) + if (!string.IsNullOrWhiteSpace(subject) && subject?.Length > 2048) throw new ArgumentException("Subject cannot exceed 2048 characters.", nameof(subject)); if (string.IsNullOrWhiteSpace(message)) @@ -74,6 +74,6 @@ public class SendEmailCommand : IRequest if (!string.IsNullOrWhiteSpace(attachmentFileName) && attachmentFileName.Length > 255) throw new ArgumentException("Attachment file name cannot exceed 255 characters.", nameof(attachmentFileName)); - return new(from, senderName, to, recipientName, subject, message, isHtml, attachment, attachmentFileName); + return new(from, senderName!, to, recipientName!, subject!, message, isHtml, attachment, attachmentFileName); } } diff --git a/LiteCharms.Models/LiteCharms.Models.csproj b/LiteCharms.Models/LiteCharms.Models.csproj index f890e79..c4cace3 100644 --- a/LiteCharms.Models/LiteCharms.Models.csproj +++ b/LiteCharms.Models/LiteCharms.Models.csproj @@ -11,7 +11,7 @@ LiteCharms.Models - 1.0.2 + 1.0.3 Khwezi Mngoma Lite Charms (PTY) Ltd Shared models for Lite Charms applications.