I was looking for how to add a list to the Included Recipient List section to an EXM MessageItem programmatically.

In Sitecore 8.2 you could do


Anyone have an idea how to achieve this in the updated API in Sitecore 9.1.1?


The following code would help you:

using System;
using Sitecore.Diagnostics;
using Sitecore.Modules.EmailCampaign;
using Sitecore.Modules.EmailCampaign.Factories;
using Sitecore.Modules.EmailCampaign.Messages;
using Sitecore.Modules.EmailCampaign.Services;

namespace Demo
    public class CustomExmManager
        private readonly IRecipientManagerFactory _recipientManagerFactory;
        private readonly IExmCampaignService _exmCampaignService;

        public CustomExmManager(IRecipientManagerFactory recipientManagerFactory, IExmCampaignService exmCampaignService)
            Assert.ArgumentNotNull((object)recipientManagerFactory, nameof(recipientManagerFactory));
            this._recipientManagerFactory = recipientManagerFactory;
            this._exmCampaignService = exmCampaignService;

        public bool AddIncludedRecipientList(Guid recipientListId, Guid messageId)
            MessageItem messageItem = this._exmCampaignService.GetMessageItem(messageId);
            return AddIncludedRecipientList(recipientListId, messageItem);

        public bool AddIncludedRecipientList(Guid recipientListId, MessageItem messageItem)
            IRecipientManager recipientManager = this._recipientManagerFactory.GetRecipientManager(messageItem);
            return recipientManager.AddIncludedRecipientListId(recipientListId);

If you already have an MessageItem object, you can remove the part where I initializes it by messageId using_exmCampaignService.

  • Is the IRecipientManagerFactory from dependencyInjection or where does it come from? – Filip Jönsson May 22 '19 at 13:44
  • 1
    @FilipJönsson From dependencyInjection. It should be there already. – Artem Prashkovich May 22 '19 at 13:53
  • 1
    @FilipJönsson has it helped? – Artem Prashkovich May 23 '19 at 7:21
  • Yes it did! Thank you! – Filip Jönsson May 23 '19 at 11:43

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.