Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Ben Palmer 168 posts 813 karma points c-trib
    1 week ago
    Ben Palmer

    Umbraco Forms - Editing Email Template


    Trying and failing to edit the default email view in Umbraco Forms in the standard "Send email" workflow.

    I'm aware that there is a workflow to send via Razor but it doesn't allow editors to add a message from the CMS like "Send email" does.

    So, two options

    1. How do I edit the template used in the "Send email" workflow type?
    2. Is it possible to add a new field to the "Send email with template (Razor)" workflow type?



  • Ben Palmer 168 posts 813 karma points c-trib
    1 week ago
    Ben Palmer

    Done quite a lot more digging and hidden away on the documentation page is this beauty:

    So for anyone else who happens to have the same issue, you can override/extend existing workflow types. Here's some sample code to show you how I did it (beware of the session "hack" - it's the only way I could find out how to pass data to the view, not ideal but it does work).

    Workflow Definition:

    using System.Web;
    using Umbraco.Core;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Attributes;
    using Umbraco.Forms.Core.Data.Storage;
    using Umbraco.Forms.Core.Enums;
    using Umbraco.Forms.Core.Persistence.Dtos;
    using Umbraco.Forms.Core.Services;
    using Umbraco.Web;
    namespace Example.Core.WorkflowTypes
        public class SendRazorEmailWorkflowType : Umbraco.Forms.Core.Providers.WorkflowTypes.SendRazorEmail
            #region Constructors
            public SendRazorEmailWorkflowType(IHttpContextAccessor httpContextAccessor, IFieldTypeStorage fieldTypeStorage, IFormStorage formStorage, IUmbracoContextAccessor umbracoContextAccessor, IPageService pageService, IWorkflowEmailService workflowEmailService)
                : base(httpContextAccessor, fieldTypeStorage, formStorage, umbracoContextAccessor, pageService, workflowEmailService)
            #region Settings
            [Setting("Email Introduction", Description = "Displayed before the records in the email body.", View = "TextArea")]
            public string EmailIntroduction { get; set; }
            [Setting("Email Body", Description = "Displayed after the introduction.", View = "TextArea")]
            public string EmailBody { get; set; }
            [Setting("Email Records Text", Description = "Displayed before the records are shown.", View = "TextArea")]
            public string EmailRecordsText { get; set; }
            [Setting("Email Outro", Description = "Displayed after the email body.", View = "TextArea")]
            public string EmailOutro { get; set; }
            [Setting("Email Link URL", Description = "Optional link, if set, a button will be displayed in the email.", View = "TextString")]
            public string EmailLinkUrl { get; set; }
            [Setting("Email Link Title", Description = "Optional link title, if the Email Link URL is set, this text will be used on the button.", View = "TextString")]
            public string EmailLinkTitle { get; set; } = "Learn more";
            [Setting("Show Records in Email", Description = "If enabled, the email will display the fields submitted.", View = "Checkbox")]
            public string ShowRecordsInEmail { get; set; }
            public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
                HttpContext.Current.Session["emailIntroduction"] = EmailIntroduction;
                HttpContext.Current.Session["emailBody"] = EmailBody;
                HttpContext.Current.Session["emailRecordsText"] = EmailRecordsText;
                HttpContext.Current.Session["emailOutro"] = EmailOutro;
                HttpContext.Current.Session["emailLinkUrl"] = EmailLinkUrl;
                HttpContext.Current.Session["emailLinkTitle"] = EmailLinkTitle;
                HttpContext.Current.Session["showRecordsInEmail"] = ShowRecordsInEmail;
                if (EmailLinkTitle.IsNullOrWhiteSpace())
                    HttpContext.Current.Session["emailLinkTitle"] = "Read more";
                return base.Execute(record, e);

    View/Razor File (I've only included how to retrieve the data here, but you can use these variables however you want from there on out):

    @inherits UmbracoViewPage<Umbraco.Forms.Core.Models.FormsHtmlModel>
        //This is an example email template where you can use Razor Views to send HTML emails
        //You can use Umbraco.TypedContent & Umbraco.TypedMedia etc to use Images & content from your site
        //directly in your email templates too
        //Strongly Typed
        //@foreach (var color in Model.GetValues("checkboxField")){}
        //@foreach(var color in Model.DynamicFields.checkboxField
        //Images need to be absolute - so fetching domain to prefix with images
        var siteDomain = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
        var assetUrl = siteDomain + "/assets/images";
        var emailIntroduction = HttpContext.Current.Session["emailIntroduction"];
        var emailBody = HttpContext.Current.Session["emailBody"];
        var emailRecordsText = HttpContext.Current.Session["emailRecordsText"];
        var emailOutro = HttpContext.Current.Session["emailOutro"];
        var emailLinkUrl = HttpContext.Current.Session["emailLinkUrl"];
        var emailLinkTitle = HttpContext.Current.Session["emailLinkTitle"];
        var showRecordsInEmail = HttpContext.Current.Session["showRecordsInEmail"];



Please Sign in or register to post replies

Write your reply to: