Sitecore things

Sitecore best practices, architectures, EXM, SPEAK...

Exploit Sitecore EXM Subscription Message Type

In Sitecore EXM, when you click the Create button in the navigation pane, you will see three message types (one-time message, subscription message and triggered message).

In the one-time and triggered message, there are some pre-defined message templates, but you won’t find anything in the subscription message.

A subscription message template is a template created from a message. For example, you create a new message based on one-time message template, and then you make some changes on the content. You want to reuse this updated message as a template next time. You can choose “Save as a Subscription message template” action.

enter image description here

After doing this, the new message template will show up in the subscription message type.

Think about the scenario that a client has several Sitecore sites. Each site has its own Email Campaign Root. The master email campaign editor updates the default newsletter message template and he wants the editors of the other sites use his changes. The subscription message template will really come in handy then.

But there is another main issue needed to be solved. The new subscription messages will only be saved in its own Email Campaign Root. How could the other roots find it?

enter image description here

Fortunately, EXM uses a provider to retrieve the subscription message templates. The provider is defined in an item called Templates in the core database. The full path is /sitecore/client/Applications/ECM/Component/Create/Subscription/Templates.

enter image description here

enter image description here

The DefaultCreateMessageInsertOptionsProvider implements ICreateMessageInsertOptionsProvider interface. This interface has one member called GetInsertOptions. Its signature is List GetInsertOptions(string managerRootId, string messageType, string database = null).

What we can do is to create a new provider also implements this interface. This provider will always load the subscription message templates from the master Email Campaign Root, no matter which current root is. So in our version of GetInsertOptions, the managerRootId will be the Id of the master Email Campaign Root, the messageType will be Sitecore.EmailCampaign.Server.Helpers.Constants.Items.MessageTypes.Subscription and the database will be the master database.

A small issue of this solution is that you have to make sure the /Email Campaign/Message Types/Subscription folder in each Email Campaign Root can’t be empty even it reads the subscription message templates from the master root. It seems that EXM will check this folder before it creates the message. A workaround is to create a new manager root branch template based on /sitecore/templates/Branches/Email Campaign/Manager Root, and add a dummy subscription message in the subscription folder.