update to configure email out
This commit is contained in:
parent
c1c30caeec
commit
f20243d02c
@ -23,5 +23,5 @@ public class DispatcherParams
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default value is string.Empty
|
/// Default value is string.Empty
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string EmailAttmt1 { get; init; } = string.Empty;
|
public string? EmailAttmt1 { get; init; } = null;
|
||||||
}
|
}
|
||||||
@ -1,8 +1,11 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.Repository;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using DigitalData.EmailProfilerDispatcher.Abstraction.Entities;
|
||||||
|
using EnvelopeGenerator.Application.Configurations;
|
||||||
using EnvelopeGenerator.Domain.Constants;
|
using EnvelopeGenerator.Domain.Constants;
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Notifications;
|
namespace EnvelopeGenerator.Application.Notifications;
|
||||||
@ -16,6 +19,11 @@ public interface ISendMailNotification : INotification
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EmailTemplateType TemplateType { get; }
|
public EmailTemplateType TemplateType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string EmailAddress { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -29,23 +37,51 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly IRepository<EmailTemplate> TempRepo;
|
protected readonly IRepository<EmailTemplate> TempRepo;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
protected readonly IRepository<EmailOut> EmailOutRepo;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual Dictionary<string, string> BodyPlaceHolders { get; } = new();
|
protected virtual Dictionary<string, string> BodyPlaceHolders { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
protected readonly MailParams MailParams;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
protected readonly DispatcherParams DispatcherParams;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual Dictionary<string, string> SubjectPlaceHolders { get; } = new();
|
protected virtual Dictionary<string, string> SubjectPlaceHolders { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ReferenceString = Envelope.Uuid
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="emailOut"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract void ConfigEmailOut(EmailOut emailOut);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tempRepo"></param>
|
/// <param name="tempRepo"></param>
|
||||||
protected SendMailHandler(IRepository<EmailTemplate> tempRepo)
|
/// <param name="emailOutRepo"></param>
|
||||||
|
/// <param name="mailParamsOptions"></param>
|
||||||
|
/// <param name="dispatcherParamsOptions"></param>
|
||||||
|
protected SendMailHandler(IRepository<EmailTemplate> tempRepo, IRepository<EmailOut> emailOutRepo, IOptions<MailParams> mailParamsOptions, IOptions<DispatcherParams> dispatcherParamsOptions)
|
||||||
{
|
{
|
||||||
TempRepo = tempRepo;
|
TempRepo = tempRepo;
|
||||||
|
EmailOutRepo = emailOutRepo;
|
||||||
|
MailParams = mailParamsOptions.Value;
|
||||||
|
DispatcherParams = dispatcherParamsOptions.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -63,15 +99,50 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
|
|||||||
?? throw new InvalidOperationException($"Receiver information is missing in the notification." +
|
?? throw new InvalidOperationException($"Receiver information is missing in the notification." +
|
||||||
$"{typeof(TNotification)}:\n {JsonConvert.SerializeObject(notification, Format.Json.ForDiagnostics)}");
|
$"{typeof(TNotification)}:\n {JsonConvert.SerializeObject(notification, Format.Json.ForDiagnostics)}");
|
||||||
|
|
||||||
temp.Subject = ReplacePlaceHolders(temp.Subject, SubjectPlaceHolders);
|
temp.Subject = ReplacePlaceHolders(temp.Subject, SubjectPlaceHolders, MailParams.Placeholders);
|
||||||
|
|
||||||
temp.Body = ReplacePlaceHolders(temp.Body, BodyPlaceHolders);
|
temp.Body = ReplacePlaceHolders(temp.Body, BodyPlaceHolders, MailParams.Placeholders);
|
||||||
|
|
||||||
|
var emailOut = new EmailOut
|
||||||
|
{
|
||||||
|
EmailAddress = notification.EmailAddress,
|
||||||
|
EmailBody = temp.Body,
|
||||||
|
EmailSubj = temp.Subject,
|
||||||
|
AddedWhen = DateTime.UtcNow,
|
||||||
|
AddedWho = DispatcherParams.AddedWho,
|
||||||
|
SendingProfile = DispatcherParams.SendingProfile,
|
||||||
|
ReminderTypeId = DispatcherParams.ReminderTypeId,
|
||||||
|
EmailAttmt1 = DispatcherParams.EmailAttmt1,
|
||||||
|
WfId = (int)EnvelopeStatus.MessageConfirmationSent,
|
||||||
|
|
||||||
|
};
|
||||||
|
ConfigEmailOut(emailOut);
|
||||||
|
await EmailOutRepo.CreateAsync(emailOut, cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ReplacePlaceHolders(string text, Dictionary<string, string> placeHolders)
|
private static string ReplacePlaceHolders(string text, params Dictionary<string, string>[] placeHoldersList)
|
||||||
{
|
{
|
||||||
|
foreach (var placeHolders in placeHoldersList)
|
||||||
foreach (var ph in placeHolders)
|
foreach (var ph in placeHolders)
|
||||||
text = text.Replace(ph.Key, ph.Value);
|
text = text.Replace(ph.Key, ph.Value);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string TextToHtml(string input)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(input)) return "";
|
||||||
|
|
||||||
|
// HTML encoding special characters
|
||||||
|
string encoded = System.Net.WebUtility.HtmlEncode(input);
|
||||||
|
|
||||||
|
// Convert tabs to (4 non-breaking spaces)
|
||||||
|
encoded = encoded.Replace("\t", " ");
|
||||||
|
|
||||||
|
// Convert line breaks to <br />
|
||||||
|
encoded = encoded.Replace("\r\n", "<br />"); // Windows
|
||||||
|
encoded = encoded.Replace("\r", "<br />"); // Mac old
|
||||||
|
encoded = encoded.Replace("\n", "<br />"); // Unix/Linux
|
||||||
|
|
||||||
|
return encoded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,17 +2,14 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
using System.ComponentModel;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Domain.Entities
|
namespace EnvelopeGenerator.Domain.Entities
|
||||||
{
|
{
|
||||||
|
[Obsolete("Use EmailDispatcher.EmailOut")]
|
||||||
[Table("TBEMLP_EMAIL_OUT")]
|
[Table("TBEMLP_EMAIL_OUT")]
|
||||||
public class EmailOut
|
internal class EmailOut
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
|||||||
@ -13,6 +13,7 @@ using Dapper;
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using DigitalData.UserManager.Domain.Entities;
|
using DigitalData.UserManager.Domain.Entities;
|
||||||
|
using DigitalData.EmailProfilerDispatcher.Abstraction.Entities;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Infrastructure;
|
namespace EnvelopeGenerator.Infrastructure;
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ public static class DIExtensions
|
|||||||
services.AddDbRepository<EGDbContext, EnvelopeDocument>(context => context.EnvelopeDocument).UseAutoMapper();
|
services.AddDbRepository<EGDbContext, EnvelopeDocument>(context => context.EnvelopeDocument).UseAutoMapper();
|
||||||
services.AddDbRepository<EGDbContext, DocumentStatus>(context => context.DocumentStatus).UseAutoMapper();
|
services.AddDbRepository<EGDbContext, DocumentStatus>(context => context.DocumentStatus).UseAutoMapper();
|
||||||
services.AddDbRepository<EGDbContext, EmailTemplate>(context => context.EmailTemplate).UseAutoMapper();
|
services.AddDbRepository<EGDbContext, EmailTemplate>(context => context.EmailTemplate).UseAutoMapper();
|
||||||
|
services.AddDbRepository<EGDbContext, EmailOut>(context => context.EMailOuts).UseAutoMapper();
|
||||||
services.AddDbRepository<EGDbContext, Envelope>(context => context.Envelopes).UseAutoMapper();
|
services.AddDbRepository<EGDbContext, Envelope>(context => context.Envelopes).UseAutoMapper();
|
||||||
services.AddDbRepository<EGDbContext, EnvelopeHistory>(context => context.EnvelopeHistories).UseAutoMapper();
|
services.AddDbRepository<EGDbContext, EnvelopeHistory>(context => context.EnvelopeHistories).UseAutoMapper();
|
||||||
services.AddDbRepository<EGDbContext, EnvelopeReceiver>(context => context.EnvelopeReceivers).UseAutoMapper();
|
services.AddDbRepository<EGDbContext, EnvelopeReceiver>(context => context.EnvelopeReceivers).UseAutoMapper();
|
||||||
|
|||||||
@ -132,7 +132,7 @@
|
|||||||
"SendingProfile": 1,
|
"SendingProfile": 1,
|
||||||
"AddedWho": "DDEnvelopGenerator",
|
"AddedWho": "DDEnvelopGenerator",
|
||||||
"ReminderTypeId": 202377,
|
"ReminderTypeId": 202377,
|
||||||
"EmailAttmt1": ""
|
"EmailAttmt1": null
|
||||||
},
|
},
|
||||||
"MailParams": {
|
"MailParams": {
|
||||||
"Placeholders": {
|
"Placeholders": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user