Support multiple email recipients in email-sending flow
Updated the `IEmailService` interface and related components to support multiple recipients in the `SendEmailAsync` method. - Replaced `Recipient` with `Recipients` in `SendEmailCommand`, `OutgoingEmailEvent`, and `EmailsController`. - Updated `SendEmailCommandValidator` to validate a collection of recipients, ensuring at least one valid email address. - Modified `LimilabsEmailService` to handle multiple recipients by iterating over the collection and adding each to the email. - Adjusted `OutgoingEmailConsumer` to process and log multiple recipients. - Updated logging and response structures to reflect the changes. These changes enable the system to handle emails with multiple recipients while maintaining proper validation and logging.
This commit is contained in:
@@ -14,5 +14,5 @@ public interface IEmailService
|
||||
/// Sends an email using the configured SMTP account.
|
||||
/// SMTP credentials are configured in appsettings.json (EmailAccount section).
|
||||
/// </summary>
|
||||
Task SendEmailAsync(EmailAccountDto from, string to, string subject, string body, bool isHtml = true, CancellationToken cancellationToken = default);
|
||||
Task SendEmailAsync(EmailAccountDto from, IEnumerable<string> recipients, string subject, string body, bool isHtml = true, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ public record SendEmailCommand : IRequest<OutgoingEmailEvent>
|
||||
public required GetSenderQuery Sender { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Recipient email address
|
||||
/// Recipient email addresses
|
||||
/// </summary>
|
||||
public required string Recipient { get; init; }
|
||||
public required IEnumerable<string> Recipients { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Email subject
|
||||
|
||||
@@ -10,13 +10,16 @@ public class SendEmailCommandValidator : AbstractValidator<SendEmailCommand>
|
||||
{
|
||||
public SendEmailCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.Recipient)
|
||||
RuleFor(x => x.Recipients)
|
||||
.NotEmpty()
|
||||
.WithMessage("Recipient is required")
|
||||
.MaximumLength(200)
|
||||
.WithMessage("Recipient must not exceed 200 characters")
|
||||
.EmailAddress()
|
||||
.WithMessage("Recipient must be a valid email address");
|
||||
.WithMessage("Recipients are required")
|
||||
.Must(x => x.Any())
|
||||
.WithMessage("At least one recipient is required")
|
||||
.ForEach(recipient => recipient
|
||||
.NotEmpty()
|
||||
.WithMessage("Recipient email must not be empty")
|
||||
.EmailAddress()
|
||||
.WithMessage("Invalid email address format"));
|
||||
|
||||
RuleFor(x => x.Subject)
|
||||
.NotEmpty()
|
||||
|
||||
@@ -11,7 +11,7 @@ public record OutgoingEmailEvent
|
||||
/// <summary>
|
||||
/// Recipient email address
|
||||
/// </summary>
|
||||
public string Recipient { get; set; } = null!;
|
||||
public IEnumerable<string> Recipients { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Email subject
|
||||
|
||||
Reference in New Issue
Block a user