5

I'm attempting to add a reply-to address to an email I'm sending via WFFM 8.1. The save action I am using is "Send Email Message." The email being sent includes the email address of the user filling out the associated form. I would like to use the user's email as the reply-to address. In the email message editor, I do not see a reply-to email option so I assume I will need to write a custom save action. My question is twofold:

  1. Is it possible to add a reply-to address to the "Send Email Message" save action with out-of-the-box WFFM?
  2. If this functionality is not available out-of-the-box, it possible to extend the functionality of the "Send Email Message" save action to include a reply-to email while preserving the following UI that accompanies the save action? enter image description here

Thanks for the help!

  • What is the function of a reply-to? For the reciever in the mail? You already have the "To:" field where you can click the down arrow to get an e-mail field (the one users fill out in the form). IF you have added an e-mail field to your form already. – Filip Jönsson Jan 24 '17 at 7:24
  • 2
    Here's a post detailing what a reply-to field does: discussions.apple.com/thread/2761914?start=0&tstart=0. Essentially, the client wants to be able to hit reply to send an email back to the individual who filled out the form rather than fishing through the email for the individual's email address and pasting it into the "To" field. – c-bro Jan 24 '17 at 13:53
  • I would suggest to use Email Experience Manager for e-mail sending and there you have much more functionality like Reply To. – Tamás Tárnok Jan 25 '17 at 22:31
  • @TamásTárnok, how would you use EXM for save action?! – Azimuth Oct 4 '18 at 7:04
5

You need to override for the SendEmail method in the processMessage pipeline (patched in the /App_config/Include/Sitecore.Forms.Config)

With something like this:

using Sitecore.Form.Core.Pipelines.ProcessMessage;
using System.Net.Mail;

namespace Arktouros
{
    public class PressMessageOverride
    {
        public void SendEmail(ProcessMessageArgs args)
        {
            SmtpClient smtpClient = new SmtpClient(args.Host);
            smtpClient.EnableSsl = args.EnableSsl;
            if (args.Port != 0)
            {
                smtpClient.Port = args.Port;
            }
            smtpClient.Credentials = args.Credentials;
            smtpClient.Send(this.GetMail(args));
        }

        private MailMessage GetMail(ProcessMessageArgs args)
        {
            MailMessage mail = new MailMessage(args.From, args.To.ToString(), args.Subject.ToString(), args.Mail.ToString())
            {
                IsBodyHtml = args.IsBodyHtml
            };
            //your reply to goes here, set to be the from address of the form being submitted
            mail.ReplyToList.Add(new MailAddress(args.From));

            if (args.CC.Length > 0)
            {
                mail.CC.Add(args.CC.ToString());
            }
            if (args.BCC.Length > 0)
            {
                mail.Bcc.Add(args.BCC.ToString());
            }
            args.Attachments.ForEach(delegate (Attachment attachment)
            {
                mail.Attachments.Add(attachment);
            });
            return mail;
        }
    }
}

then update the config file to point to your new class:

replace: <processor type="Sitecore.Form.Core.Pipelines.ProcessMessage.ProcessMessage, Sitecore.Forms.Core" method="SendEmail" />

with

<processor type="NamespaceOfYourClass, YourDLL" method="SendEmail" />

and away you go, for info this is not fully tested, but should work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.