From bdc02da8960d48eba7c11f35784b8b06d8a96df3 Mon Sep 17 00:00:00 2001 From: Santhosh Bomma Date: Mon, 4 Dec 2023 22:47:32 -0800 Subject: [PATCH] added changes to use the global email address from email template --- src/Services/Helpers/EmailHelper.cs | 35 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Services/Helpers/EmailHelper.cs b/src/Services/Helpers/EmailHelper.cs index 7ddff971..9166f54f 100644 --- a/src/Services/Helpers/EmailHelper.cs +++ b/src/Services/Helpers/EmailHelper.cs @@ -69,20 +69,15 @@ public EmailContentModel PrepareEmailContent(Guid subscriptionID, Guid planGuId, var eventData = this.planEventsMappingRepository.GetPlanEvent(planGuId, subscriptionEvent.EventsId); - if (eventData != null) - { - toReceipents = eventData.SuccessStateEmails; - copyToCustomer = Convert.ToBoolean(eventData.CopyToCustomer); - } - - if (string.IsNullOrEmpty(toReceipents)) - { - throw new Exception(" Error while sending an email, please check the configuration. "); - } - + //First add To, Cc, Bcc email addresses from email template if (emailTemplateData != null) { - if (!string.IsNullOrEmpty(toReceipents) && !string.IsNullOrEmpty(emailTemplateData.Cc)) + if (!string.IsNullOrEmpty(emailTemplateData.ToRecipients)) + { + toReceipents = emailTemplateData.ToRecipients; + } + + if (!string.IsNullOrEmpty(emailTemplateData.Cc)) { ccReceipents = emailTemplateData.Cc; } @@ -95,6 +90,22 @@ public EmailContentModel PrepareEmailContent(Guid subscriptionID, Guid planGuId, subject = emailTemplateData.Subject; } + //If the plan event data contains plan specific ToEmailAddress then override the above + if (eventData != null) + { + if (!string.IsNullOrEmpty(eventData.SuccessStateEmails)) + { + toReceipents = eventData.SuccessStateEmails; + } + + copyToCustomer = Convert.ToBoolean(eventData.CopyToCustomer); + } + + if (string.IsNullOrEmpty(toReceipents)) + { + throw new Exception(" Error while sending an email, please check the configuration. To email empty"); + } + return FinalizeContentEmail(subject, body, ccReceipents, bccReceipents, toReceipents, copyToCustomer); }