Sending email campaigns programmatically

Version: 10.0

The Email Experience Manager API (IClientApiService) can only be used on the Content Delivery (CD) role. To send regular and automated email campaigns programmatically from the Content Management (CM) role, follow the examples below.

Automated email campaigns

To send automated email campaigns, use the message bus, which is also used on the CD role.

RequestResponse
IMessageBus<AutomatedMessagesBus> automatedMessageBus = 
ServiceLocator.ServiceProvider.GetService<IMessageBus<AutomatedMessagesBus>>();

AutomatedMessage automatedMessage = new AutomatedMessage()
{
    ContactIdentifier = contactIdentifier,
    MessageId = emailCampaignId
};
automatedMessageBus.Send(automatedMessage);

Regular email campaigns

To send regular email campaigns, use the Sending Manager.

Note

The ISendingManagerFactory is provided in the the Sitecore.EmailCampaign.Cm package, under the  Sitecore.EmailCampaign.Cm.Factories+ namespace.

RequestResponse
var sendingManagerFactory =
ServiceLocator.ServiceProvider.GetService<ISendingManagerFactory>();
var campaignService =
ServiceLocator.ServiceProvider.GetService<IExmCampaignService>();

MessageItem emailCampaign = campaignService.GetMessageItem(emailCampaignId);

ISendingManager sendingManager =
sendingManagerFactory.GetAsyncSendingManager(emailCampaign);

sendingManager.SendMessage();

Do you have some feedback for us?

If you have suggestions for improving this article,