Copied to clipboard

Flag this post as spam?

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

  • Hayden 32 posts 170 karma points
    Aug 31, 2017 @ 00:50

    How to add reply-to & bcc functionality to umbraco forms


    I'm needed to add a reply-to field & a bcc field to umbraco forms. I've created a custom workflow which is an extension of the "Send Email".

    Simply create a new file in your app_code folder (can call it anything) say SendEmailExtended.cshtml

    Go into umbraco forms and create a workflow! easy as that..

    using System;
    using System.Net.Mail;
    using System.Collections.Generic;
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Mvc;
    using System.Xml;
    using System.Xml.XPath;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Attributes;
    using Umbraco.Forms.Core.Enums;
    using Umbraco.Forms.Data.Storage;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace Contour.SharedSource.Providers.WorkflowTypes
    public class SendEmailExtended : WorkflowType
        [Umbraco.Forms.Core.Attributes.Setting("Email", description = "Enter the receiver email", view = "TextField")]
        public string Email { get; set; }
        [Umbraco.Forms.Core.Attributes.Setting("SenderEmail", description = "Enter the sender email (if blank it will use the settings from /config/umbracosettings.config)", view = "TextField")]
        public string SenderEmail { get; set; }
        [Umbraco.Forms.Core.Attributes.Setting("BCC", description = "Enter a BCC email address", view = "TextField")] 
        public string BCC { get; set; }
        [Umbraco.Forms.Core.Attributes.Setting("Reply To", description = "Enter a Reply-To email address", view = "TextField")] 
        public string replyTo { get; set; }
        [Umbraco.Forms.Core.Attributes.Setting("Subject", description = "Enter the subject", view = "TextField")]
        public string Subject { get; set; }
        [Umbraco.Forms.Core.Attributes.Setting("Message", description = "Enter the intro message",  view = "TextArea" )]
        public string Message { get; set; }
        public SendEmailExtended()
            this.Id = new Guid("FC92552F-4063-4CC2-ACC9-B1DF7EEA151A");
            this.Name = "Send Email Extended";
            this.Description = "An extenstion of send email with functionality to BCC & Reply-To";
            this.Icon = "icon-message";
        public override List<Exception> ValidateSettings()
            List<Exception> l = new List<Exception>();
            if (string.IsNullOrEmpty(Email))
                l.Add(new Exception("'Email' setting not filled out'"));
            if (string.IsNullOrEmpty(Message))
                l.Add(new Exception("'Message' setting not filled out'"));
            return l;
        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
            m.From = new System.Net.Mail.MailAddress(umbraco.UmbracoSettings.NotificationEmailSender);
            m.Subject = Subject;
            m.IsBodyHtml = true;
            // ATTACH EMAIL ADDRESS'
            if (Email.Contains(';'))
                string[] emails = Email.Split(';');
                foreach (string email in emails)
            // ATTACH BCC ADDRESS'
            if (!string.IsNullOrEmpty(BCC)) { m.Bcc.Add(BCC); }
            if (!string.IsNullOrEmpty(replyTo)) { m.ReplyToList.Add(replyTo); }
            /*RecordsViewer viewer = new RecordsViewer();
            XmlNode xml = viewer.GetSingleXmlRecord(record, new System.Xml.XmlDocument());*/
            var xml = record.ToXml(new System.Xml.XmlDocument());
            XPathNavigator navigator = xml.CreateNavigator();
            XPathExpression selectExpression = navigator.Compile("//fields/child::*");
            selectExpression.AddSort("@pageindex", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
            selectExpression.AddSort("@fieldsetindex", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
            selectExpression.AddSort("@sortorder", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
            XPathNodeIterator nodeIterator = navigator.Select(selectExpression);
            string list = "<dl>";
            while( nodeIterator.MoveNext() ){
                list += "<dt><strong>" + nodeIterator.Current.SelectSingleNode("caption").Value + ": </strong><dt><dd>";
                XPathNodeIterator values = nodeIterator.Current.Select(".//value");
                    list += values.Current.Value.Trim() + "<br/>";
                list += "</dd>";
            list += "</dl>";
            m.Body = "<p>" + Message + "</p>" + list;
            System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient();
            return WorkflowExecutionStatus.Completed;

    Cheers, Hayden

  • Hayden 32 posts 170 karma points
    Aug 31, 2017 @ 00:50

    Please see the first post for the answer ->

  • Colm Garvey 40 posts 65 karma points
    Sep 30, 2017 @ 14:09
    Colm Garvey

    Thanks Hayden, this looks to be ideal for my purposes but it doesn't appear to be working on Umbraco Cloud unless I've missed something?

    1. Create SendExtendedEmail.cshtml in App_Code
    2. Add/Commit/Push to Umbraco Cloud.
    3. Restart Environment


    Check Workflow.. no new "Send Extended"

    Any ideas?

  • Hayden 32 posts 170 karma points
    Oct 02, 2017 @ 03:15

    Hi Colm,

    Unfortunately I haven't tried to use it on Umbraco Cloud before but I'd assume it would be a similar process.

    Goodluck on your search, if you find the answer i'd love to hear for future reference :).

    Cheers, Hayden

  • Colm Garvey 40 posts 65 karma points
    Nov 26, 2017 @ 21:14
    Colm Garvey

    Hi Hayden, thought I had a workaround for this but find myself needing replyTo functionality on another project now.

    Just to avoid assumptions, can you just confirm the exactly directory this file needs to be located in in order to be picked up as a custom workflow?

    I had assumed ~\Views\Partials\Forms\Fieldtypes

    but you know what they say about assume...



  • Hayden 32 posts 170 karma points
    Nov 26, 2017 @ 21:16

    Hi Colm,

    Putting this file within your /App_Code/ folder should do the trick :).

    Last time I used this code was 7.5 ish, haven't tested with 7.6+ but should still work fine.

    EDIT: If you don't have an App_Code folder, you can just create one in your root directory.


  • Colm Garvey 40 posts 65 karma points
    Oct 11, 2018 @ 20:07
    Colm Garvey

    I think I may know what the problem is. Does the solution as detailed above support "Magic Strings" (so that you can dynamically set the Sender's email address as the "Reply To" address?)

Please Sign in or register to post replies

Write your reply to: