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:
@@ -49,7 +49,7 @@ public sealed class OutgoingEmailConsumer : IAsyncDisposable
|
||||
// Send email via SMTP (SMTP config is injected in IEmailService via IOptions)
|
||||
await EmailService.SendEmailAsync(
|
||||
oMailEvent.Sender,
|
||||
oMailEvent.Recipient,
|
||||
oMailEvent.Recipients,
|
||||
oMailEvent.Subject,
|
||||
oMailEvent.Body,
|
||||
isHtml: oMailEvent.IsHtml);
|
||||
@@ -65,7 +65,7 @@ public sealed class OutgoingEmailConsumer : IAsyncDisposable
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger?.LogError(ex, "Failed to process email [To={To}, Subject={Subject}] message: DeliveryTag={DeliveryTag}. Moving to DLQ (NO retry).", oMailEvent?.Recipient, oMailEvent?.Subject, args.DeliveryTag);
|
||||
logger?.LogError(ex, "Failed to process email [To={To}, Subject={Subject}] message: DeliveryTag={DeliveryTag}. Moving to DLQ (NO retry).", oMailEvent?.Recipients, oMailEvent?.Subject, args.DeliveryTag);
|
||||
|
||||
// TODO: Error Reporting Strategy
|
||||
// Option 1: Separate RabbitMQ Queue (emailprofiler.errors)
|
||||
|
||||
@@ -27,7 +27,7 @@ public class LimilabsEmailService(
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
|
||||
public async Task SendEmailAsync(EmailAccountDto from, string to, string subject, string body, bool isHtml = true, CancellationToken cancellationToken = default)
|
||||
public async Task SendEmailAsync(EmailAccountDto from, IEnumerable<string> recipients, string subject, string body, bool isHtml = true, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var smtp = new Smtp();
|
||||
|
||||
@@ -37,7 +37,10 @@ public class LimilabsEmailService(
|
||||
|
||||
var builder = new MailBuilder();
|
||||
builder.From.Add(new MailBox(from.Username));
|
||||
builder.To.Add(new MailBox(to));
|
||||
|
||||
foreach (var recipient in recipients)
|
||||
builder.To.Add(new MailBox(recipient));
|
||||
|
||||
builder.Subject = subject;
|
||||
|
||||
if (isHtml)
|
||||
|
||||
Reference in New Issue
Block a user