Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

Custom SendEmailAfterSubmittionActor - Model is empty (list of EmailTemplateActorModel)

$
0
0

I have extended the built-in SendEmailAfterSubmissionActor from EPiServer Forms in order to wrap the contents of the e-mail from the "Message" field from the "Send email after form submission" pop-up in EPiServer with a branded e-mail template we have designed for our client. This same e-mail template is a HTML file we also use for custom e-mails we send from the website.

After doing some research I appear to have the entire class set up correctly now, but upon executing it the list of EmailTemplateActorModel instances which should represent each e-mail configured to send from within EPiServer is empty and therefore, a portion of our code is skipped by and the e-mail is sent regardless, sans custom e-mail template. Judging from all the examples I found online this shouldn't be the case. My class and the Run() method inside are being hit as proven when I run the website in Visual Studio's debug mode. But the Model object is always an empty list of EmailTemplateActorModel, causing the foreach to be skipped. Does anyone have any ideas as to what is going wrong here? I have included an excerpt below, somewhat trimmed for brevity:

public class CustomSendEmailAfterSubmissionActor : SendEmailAfterSubmissionActor
    {
        private static readonly ILogger Logger = LogManager.GetLogger();
        public override object Run(object input)
        {
            try
            {
                var emailTemplate = EmailHelpers.GetEmailTemplate("template.html");
                var emailList = Model as IEnumerable<EmailTemplateActorModel>; // This is always an empty list, even without casting
                if (!string.IsNullOrEmpty(emailTemplate))
                {
                    // ... removed irrelevant code here
                    foreach (EmailTemplateActorModel email in emailList)
                    {
                        email.Body = new XhtmlString(
                            emailTemplate
                                .Replace("#Subject#", email.Subject)
                                .Replace("#Content#", email.Body.ToHtmlString())
                                .Replace("#CurrentYear#", DateTime.Now.Year.ToString())
                        );
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"Error while adding e-mail template to EPiServer Forms SendEmailAfterSubmissionActor", ex);
            }
            return base.Run(input);
        }
    }

Viewing all articles
Browse latest Browse all 8020

Trending Articles