3

We are planning to alter the "Reply to" from the message template while sending the email using EXM in Sitecore 10.1.2. Can we pass any value into this field for automated email sends? enter image description here

  1. Is it possible to use token ($email or [email]) in the "Reply to" field in the email template, currently I see it shows error when I try to do that?

  2. If this functionality is not available out-of-the-box, is it possible to extend the functionality to pass any value into this field for automated email sends?

1 Answer 1

1

It is not possible out of the box. I'm not sure about 10.1, but in 9.1 you needed to:

  • update regex for Reply to input value in Sitecore config:
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"  xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore>
    <fromReplyToEmailRegexValidator>
      <param desc="regexValue">^(\$[a-zA-Z0-9\-_]+\$)?([a-zA-Z0-9\+\-_\!\$\%\&amp;\*\?]+(?:\.[a-zA-Z0-9\+\-_\'\!\$\%\&amp;\*\?]+)*@(([a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9]+)+)|(\[\d{1,3}(\.\d{1,3}){3}\])))?$</param>
    </fromReplyToEmailRegexValidator>
  </sitecore>
</configuration>
  • add your processor to SendEmail pipeline before Sitecore.EmailCampaign.Cm.Pipelines.SendEmail.SendEmail, Sitecore.EmailCampaign.Cm processor and replace token value, e.g. like that:
public class ReplaceTokenInReplyTo
{
    public void Process(SendMessageArgs args)
    {
        if (args.CustomData["EmailMessage"] is EmailMessage message && message.ReplyTo != null)
        {
            var reply = message.ReplyTo;

            var indexOf = reply.IndexOf('$');
            var lastIndexOf = reply.LastIndexOf('$');

            if (indexOf != lastIndexOf)
            {
                var token = reply.Substring(indexOf, lastIndexOf - indexOf + 1);
                var replyTo = args.EcmMessage.ReplaceTokens(token);
                if (!string.IsNullOrEmpty(replyTo) 
                    && replyTo != token 
                    && new EmailAddressAttribute().IsValid(replyTo))
                {
                    message.ReplyTo = replyTo;
                }
                else
                {
                    message.ReplyTo = message.ReplyTo.Replace(token, string.Empty);
                }
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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