feat(SendEmailBehavior): add SendEmailBehavior for sending final emails after PDF burn
- Implements IPipelineBehavior<BurnPdfCommand, byte[]> to send emails to creator and receivers. - Logs debug information when sending emails and warnings if email sending is skipped. - Uses Envelope's FinalEmailType to determine whether to send emails.
This commit is contained in:
parent
d1513dab5e
commit
40cc467b47
@ -91,6 +91,7 @@ public static class DependencyInjection
|
||||
cfg.AddBehavior<CreateHistoryBehavior>();
|
||||
cfg.AddBehavior<SavePdfBehavior>();
|
||||
#if WINDOWS
|
||||
cfg.AddBehavior<SendEmailBehavior>();
|
||||
cfg.AddBehavior<WritePdfBehavior>();
|
||||
cfg.AddBehavior<PdfMergeBehavior>();
|
||||
cfg.AddBehavior<AddReportBehavior>();
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Pdf.Behaviors;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
|
||||
{
|
||||
private readonly ILogger<SendEmailBehavior> _logger;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public SendEmailBehavior(ILogger<SendEmailBehavior> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="next"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<byte[]> Handle(BurnPdfCommand request, RequestHandlerDelegate<byte[]> next, CancellationToken cancel)
|
||||
{
|
||||
var docResult = await next(cancel);
|
||||
|
||||
var mailToCreator = request.Envelope!.FinalEmailToCreator;
|
||||
var mailToReceivers = request.Envelope.FinalEmailToReceivers;
|
||||
|
||||
if (mailToCreator is not null && mailToCreator != (int)FinalEmailType.No)
|
||||
{
|
||||
_logger.LogDebug("Sending email to creator ...");
|
||||
SendFinalEmailToCreator(request.Envelope); // , pAttachment
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("No SendFinalEmailToCreator - mailToCreator [{mailToCreator}] <> [{FinalEmailType.No}] ",
|
||||
mailToCreator, FinalEmailType.No);
|
||||
}
|
||||
|
||||
if (mailToReceivers != (int)FinalEmailType.No)
|
||||
{
|
||||
_logger.LogDebug("Sending emails to receivers...");
|
||||
SendFinalEmailToReceivers(request.Envelope); // , pAttachment
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("No SendFinalEmailToReceivers - mailToReceivers [{mailToReceivers}] <> [{FinalEmailType.No}] ",
|
||||
mailToReceivers, FinalEmailType.No);
|
||||
}
|
||||
|
||||
return docResult;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user