Stable email sender
This commit is contained in:
@@ -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