5

We are using EXM 3.4 and trying to improve our mail spam test scores and I found that mailtester tells that missing alt attribute on the mail-open tracking pixel gives -0.5 score.

enter image description here

I tried to disassemble some dlls and found that its hardcoded into HtmlMailBase abstract class Sitecore.Modules.EmailCampaign.Messages.HtmlMailBase, Sitecore.EmailCampaignand think there is no way to inject into any config to change that, am I right?

Adding empty alt="" attribute should fix the problem.

3

It seems that buried deep inside of EXM, they manually generate this link. I do think the proper solution is probably seeing if the EXM Team can make this image element a little more easily accessible or add in the alt attribute. That being said, I did find a workaround. It might even be a hack!

Workaround/Hack

There is one Pipeline that can be affected, where we can add in this alt attribute to this image tag before sending.

The pipeline to reference is /sitecore/pipelines/SendEmail.

In this pipeline, the processor "FillEmail" is what actually takes the Message Body and converts it into a email packet. Putting a Processor, say called AddAltAttribute before FillEmail provides us a space to do some magic.

Below is the processor that I came up with to add the alt attribute to the RegisteredEmailOpened image.

AddAltAttribute Processor

using System.IO;
using System.Linq;
using HtmlAgilityPack;
using Sitecore.Modules.EmailCampaign.Core.Pipelines;
using Sitecore.StringExtensions;

namespace SitecoreHacker.Sandbox.EmailCampaign.Pipelines.SendEmail
{
    public class AddAltAttribute
    {
        public void Process(SendMessageArgs args)
        {
            if (args.EcmMessage == null)
                return;

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(args.EcmMessage.Body);

            var docNode =
                htmlDoc.DocumentNode
                    .Descendants("img");

            var foundElement = docNode.FirstOrDefault(node => node.HasAttributes && node.Attributes["src"].Value.Contains("RegisterEmailOpened"));

            if (foundElement == null)
                return;

            foundElement.Attributes.Add("alt", "");

            string result = null;
            using (var writer = new StringWriter())
            {
                htmlDoc.Save(writer);
                result = writer.ToString();
            }

            if (result.IsNullOrEmpty())
                return;


            //Set Back in Args
            args.EcmMessage.Body = result;
        }
    }
}

Patch Config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <SendEmail>
        <processor type="SitecoreHacker.Sandbox.EmailCampaign.Pipelines.SendEmail.AddAltAttribute, SitecoreHacker.Sandbox"
                   patch:before="*[@type='Sitecore.EmailCampaign.Cm.Pipelines.SendEmail.FillEmail, Sitecore.EmailCampaign.Cm']" />
      </SendEmail>
    </pipelines>
  </sitecore>
</configuration>

Considerations

  • Putting too much, heavy logic in the SendEmail pipeline can have a negative effect on the speed of dispatches. Ensure that whatever logic you use, it is completely optimized.
  • The above code is provided as an example. No performance tests were utilized.
  • It works ok, but the only doubt I have is that parsing DOM an HtmlDocument is quite heavy operation and takes long time to execute... – Volodymyr Hil Mar 16 '17 at 10:28
  • 1
    Hence my considerations. I did try every which way all the way up to customizing DispatchTask. But ran into many issues trying to get this to work. This was the last point I could find that didn't include rewriting EXM. – Pete Navarra Mar 16 '17 at 10:34
  • 1
    Lets wait then for EXM fix in new versions :) – Volodymyr Hil Mar 16 '17 at 12:01

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.