Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
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".
https://pastebin.com/SnfmDrSf
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) { m.To.Add(email.Trim()); } }else{ m.To.Add(Email); } // ATTACH BCC ADDRESS' if (!string.IsNullOrEmpty(BCC)) { m.Bcc.Add(BCC); } // ATTACH REPLY TO ADDRESS' 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"); while(values.MoveNext()) 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(); s.Send(m); return WorkflowExecutionStatus.Completed; } } }
Cheers, Hayden
Please see the first post for the answer -> https://pastebin.com/SnfmDrSf
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?
Wait...
Check Workflow.. no new "Send Extended"
Any ideas?
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 :).
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...
Cheers,
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.
Goodluck!
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?)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to add reply-to & bcc functionality to umbraco forms
Hi,
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".
https://pastebin.com/SnfmDrSf
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..
Cheers, Hayden
Please see the first post for the answer -> https://pastebin.com/SnfmDrSf
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?
Wait...
Check Workflow.. no new "Send Extended"
Any ideas?
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
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...
Cheers,
Colm
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.
Goodluck!
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?)
is working on a reply...