Creating a custom message type class

Abstract

Create and use custom message types, which also requires a custom type resolver.

The Email Experience Manager component lets developers create and use custom types of message items. The default EXM message types are mapped to the appropriate class in the code by the TypeResolver class. To use a custom message type class, you must also create a custom type resolver to map your message type correctly.

To create a custom message type class:

  1. Derive a custom message type class from either the MessageItem class or one of its descendants:

    • The TextMail class

    • The HtmlMail class

    • The WebPageMail class

    • The ABTestMessage class

  2. Define a message template for the new message type.

  3. Override the Clone() method on your custom message type class or it will fail during dispatch.

  4. Derive a custom type resolver class from the Sitecore.Modules.EmailCampaign.Core.TypeResolver class.

  5. In the Sitecore.EmailExperience.Core.config file, patch the exm/typeResolver setting with your custom type resolver.

  6. Override the GetCorrectMessageObject method in the class that you derived from the TypeResolver class.

    Example:

    public class NewMail : MessageItem
    {
    public static bool IsCorrectMessageItem(Item item) 
      { 
        return ItemUtilExt.IsTemplateDescendant(item, TemplateIds.NewMessageTemplate); 
      }
    ...
    }
    public class NewTypeResolver : TypeResolver
    {
      public override MessageItem GetCorrectMessageObject(Item item)
      {
        var result = NewMail.FromItem(item);
        return result != null ? result : base.GetCorrectMessageObject(item);
      }
    ...
    }