feat(client): add MessagingServiceClient and dependency injection extensions
Introduce the Email contract and MessagingServiceClient that send mail through the Application layer via MediatR, and add AddMessagingServiceClient overloads for delegate- and IConfiguration-based setup. Remove the empty client DI placeholders.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.EmailAccounts.Queries;
|
||||
using DigitalData.MessagingService.Application.EmailSending.Commands;
|
||||
using MediatR;
|
||||
|
||||
namespace DigitalData.MessagingService.Client;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class MessagingServiceClient(ISender sender)
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="email"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SendAsync(Email email, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await sender.Send(new PublishEmailViaSmtpCommand()
|
||||
{
|
||||
Sender = new GetEmailAccountQuery()
|
||||
{
|
||||
Username = email.From
|
||||
},
|
||||
Recipients = email.To,
|
||||
Subject = email.Subject,
|
||||
Body = email.Body,
|
||||
IsHtml = email.IsHtml
|
||||
}, cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user