---
title: "Sending email campaigns programmatically"
slug: "sending-email-campaigns-programmatically"
abstract: "How to send regular and automated email campaigns programmatically from the Content Delivery (CD) role using the Email Experience Manager API."
---
# Sending email campaigns programmatically

The Email Experience Manager API ([IClientApiService](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html "The Email Experience Manager Client API")) 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.

<details>
<summary><h2>Automated email campaigns</h2></summary>

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

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

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

```

</details>

<details>
<summary><h2>Regular email campaigns</h2></summary>

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.

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

MessageItem emailCampaign = campaignService.GetMessageItem(emailCampaignId);

ISendingManager sendingManager =
sendingManagerFactory.GetAsyncSendingManager(emailCampaign);

sendingManager.SendMessage();

```

</details>