November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hi Nilakantha,
There's no such event on "Create email template".
As far as I know there's only way to validate emails which are used in "Send mail after submission" section that is you have to hook into Content's Publishing Event.
My sample code
using EPiServer.Framework; using System.Collections.Generic; using System.Linq; using EPiServer.Framework.Initialization; using EPiServer.Core; using EPiServer.ServiceLocation; using EPiServer; using EPiServer.Forms.Implementation.Elements; using EPiServer.Forms.Implementation.Actors; namespace DebugForms_9.Business.Initialization { [ModuleDependency(typeof(EPiServer.Forms.EditView.InitializationModule), typeof(EPiServer.Web.InitializationModule), typeof(EPiServer.Shell.ShellInitialization))] public class FormsInit : IInitializableModule { private IContentEvents _contentEvents; public void Initialize(InitializationEngine context) { if (_contentEvents == null) { _contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>(); } _contentEvents.PublishingContent += PublishingContent; } public void Uninitialize(InitializationEngine context) { if (_contentEvents == null) { _contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>(); } _contentEvents.PublishingContent -= PublishingContent; } /// <summary> /// Hook to CMS's PublishedContent for updating structure if needed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PublishingContent(object sender, ContentEventArgs e) { // validate email in Actor template if (!(e.Content is FormContainerBlock)) { return; } var emailActorModels = e.Content.Property.GetPropertyValue<IEnumerable<EmailTemplateActorModel>>("SendEmailAfterSubmissionActor"); if (emailActorModels == null || emailActorModels.Count() == 0) { return; } foreach(var model in emailActorModels) { var fromEmail = model.FromEmail; if (!string.IsNullOrWhiteSpace(fromEmail) && !fromEmail.EndsWith("@episerver.com")) { e.CancelAction = true; e.CancelReason = "Must be an episerver email address"; } } } } }
Thanks Quan. Just wondering if there will be any performance implication as we are intercepting publish event of all content types (although we are then checking for forms only)
Nilakantha
Hi Nilakantha,
In my opinion, I don't think we'll have problem with this because CMS.Core exposes events for us to do such this thing. Moreover, the logic is not complicated and does not consume much resources.
Our addons use Core's events also.
/Quan
Hello,
I have a requirement to validate the email address that is used on "Send email after submission". Only company email address can be used.
Can we use any Form API that handles the "Add" event on "Create email template" while creating/configuring a form?
Thanks
Nilakantha