Stable email sender
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
<!-- Nuget Package Details -->
|
||||
<PropertyGroup>
|
||||
<PackageId>LiteCharms.Features</PackageId>
|
||||
<Version>1.0.12</Version>
|
||||
<Version>1.0.14</Version>
|
||||
<Authors>Khwezi Mngoma</Authors>
|
||||
<Company>Lite Charms (PTY) Ltd</Company>
|
||||
<Description>Feature components for Lite Charms applications.</Description>
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SendEmailCommandHandler(IOptions<SmtpSettings> 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)
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SendEmailCommand : IRequest<Result>
|
||||
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<Result>
|
||||
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<Result>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user