Add support for email attachments in SendEmailCommand
Enhanced the email-sending workflow to support attachments: - Updated `SendEmailCommand` with an `Attachments` property. - Added `WithAttachments` method to handle attachment initialization. - Modified `EmailsController` to accept file uploads via `IFormFileCollection`. - Implemented `BuildAttachmentsAsync` to process uploaded files. - Updated `EmailMappingProfile` to map `Attachments` to `EmailContext`. - Adjusted `SendEmail` endpoint to consume `multipart/form-data`. - Enhanced `SendEmail` response to include the queued event ID. - Updated project file to include Swagger infrastructure folder. These changes enable handling of email attachments and improve API functionality.
This commit is contained in:
@@ -14,6 +14,7 @@ public class EmailMappingProfile : Profile
|
||||
// SendEmailCommand -> Email
|
||||
// Sender is resolved via MediatR in the handler and set separately after mapping.
|
||||
CreateMap<SendEmailCommand, EmailContext>()
|
||||
.ForMember(dest => dest.Sender, opt => opt.Ignore());
|
||||
.ForMember(dest => dest.Sender, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using DigitalData.MessagingService.Application.EmailAccount.Queries;
|
||||
using DigitalData.MessagingService.Domain.Exceptions;
|
||||
using DigitalData.MessagingService.Abstraction;
|
||||
using MediatR;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DigitalData.MessagingService.Application.EmailSending.Commands;
|
||||
|
||||
@@ -32,6 +33,16 @@ public record SendEmailCommand : IRequest<Guid>
|
||||
/// Is HTML email (default: true)
|
||||
/// </summary>
|
||||
public bool IsHtml { get; init; } = true;
|
||||
|
||||
[JsonIgnore]
|
||||
internal IEnumerable<EmailAttachmentContext> Attachments { get; private init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new command instance with the supplied attachments.
|
||||
/// Called by the controller after resolving uploaded files.
|
||||
/// </summary>
|
||||
public SendEmailCommand WithAttachments(IEnumerable<EmailAttachmentContext> attachments)
|
||||
=> this with { Attachments = attachments };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user