2

I have enabled CDN images on my CD servers to reduce my media load. https://doc.sitecore.com/en/developers/93/sitecore-experience-manager/enabling-cdn.html

But since EXM messages are generated on the CM server and you are not supposed to use CDN on the CM server. How can I make my EXM generate the emails with CDN media. I can't find a media path or patch just for EXM.

2

I could not find anything about EXM and CDN urls. I guess it is expected in the scaled environment, the EXM dispatcher would be on its own server witn CDN turned on.

For my CM environment, I added a new processor to the modifyImageLink pipeline that changes the server url to the CDN url via configs.

namespace Client.Project.EmailCampaign.Pipelines.GenerateLink
{
    using Sitecore.Diagnostics;
    using Sitecore.Modules.EmailCampaign.Core.Pipelines.GenerateLink;

    public class GenerateImageCdnLink : GenerateLinkProcessor
    {
        public override void Process(GenerateLinkPipelineArgs args)
        {
            Assert.IsNotNull((object)args, "Arguments can't be null");
            Assert.IsNotNull((object)args.Url, "Url can't be null");

            bool.TryParse(Sitecore.Configuration.Settings.GetSetting("ExmImageCdnEnabled"), out var exmEnabled);
            var cdnUrl = Sitecore.Configuration.Settings.GetSetting("ExmImageCdnUrl");

            if (!exmEnabled)
                return;

            if (string.IsNullOrEmpty(cdnUrl))
                return;

            args.Url = args.Url.Replace(args.ServerUrl, cdnUrl);

            args.GeneratedUrl = args.Url;
        }
    }
}

And the config

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <sitecore>
        <pipelines>
            <modifyImageLink>
                <processor type="Client.Project.EmailCampaign.Pipelines.GenerateLink.GenerateImageCdnLink, Client.Project.EmailCampaign"
                    patch:after="processor[@type='Sitecore.Modules.EmailCampaign.Core.Pipelines.GenerateLink.ImageLink.GenerateImageLink, Sitecore.EmailCampaign']"
                    resolve="true"/>
            </modifyImageLink>
        </pipelines>        
        <settings>
            <setting name="ExmImageCdnEnabled" value="true"/>
            <setting name="ExmImageCdnUrl" value="https://mysite-test-cdn.azureedge.net"/>
        </settings>
    </sitecore>
</configuration>

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.