---
title: Notifications
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

## Notification gateways

### Creating a notification gateway

```csharp

// Creates a new notification gateway object
NotificationGatewayInfo newGateway = new NotificationGatewayInfo();

// Sets the gateway properties
newGateway.GatewayDisplayName = "New gateway";
newGateway.GatewayName = "NewGateway";
newGateway.GatewayAssemblyName = "CustomNotificationGateways";
newGateway.GatewayClassName = "NewGateway";
newGateway.GatewayDescription = "This is a notification gateway created through the API.";
newGateway.GatewaySupportsEmail = true;
newGateway.GatewaySupportsPlainText = true;
newGateway.GatewaySupportsHTMLText = true;
newGateway.GatewayEnabled = true;

// Saves the new notification gateway to the database
NotificationGatewayInfoProvider.SetNotificationGatewayInfo(newGateway);

```

[> Back to list of examples](#notifications-toc)

### Updating a notification gateway

```csharp

// Gets the notification gateway
NotificationGatewayInfo updateGateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("NewGateway");
if (updateGateway != null)
{
    // Updates the gateway properties
    updateGateway.GatewayDisplayName = updateGateway.GatewayDisplayName.ToLowerCSafe();

    // Saves the updated gateway to the database
    NotificationGatewayInfoProvider.SetNotificationGatewayInfo(updateGateway);
}

```

[> Back to list of examples](#notifications-toc)

### Updating multiple notification gateways

```csharp

// Gets all notification gateways whose code name starts with 'New'
ObjectQuery<NotificationGatewayInfo> gateways = NotificationGatewayInfoProvider.GetNotificationGateways().WhereStartsWith("GatewayName", "New");

// Loops through individual gateways
foreach (NotificationGatewayInfo gateway in gateways)
{
    // Updates the gateway properties
    gateway.GatewayDisplayName = gateway.GatewayDisplayName.ToUpper();

    // Saves the modified notification gateway to the database
    NotificationGatewayInfoProvider.SetNotificationGatewayInfo(gateway);
}

```

[> Back to list of examples](#notifications-toc)

### Deleting a notification gateway

```csharp

// Gets the notification gateway
NotificationGatewayInfo deleteGateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("NewGateway");

if (deleteGateway != null)
{
    // Deletes the notification gateway
    NotificationGatewayInfoProvider.DeleteNotificationGatewayInfo(deleteGateway);
}

```

[> Back to list of examples](#notifications-toc)

## Notification templates

### Creating a notification template

```csharp

// Creates a new notification template object
NotificationTemplateInfo newTemplate = new NotificationTemplateInfo();

// Sets the notification template properties
newTemplate.TemplateDisplayName = "New template";
newTemplate.TemplateName = "NewTemplate";
newTemplate.TemplateSiteID = SiteContext.CurrentSiteID;

// Saves the notification template to the database
NotificationTemplateInfoProvider.SetNotificationTemplateInfo(newTemplate);

// Gets a notification gateway
NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("NewGateway");

if (gateway != null)
{
    // Creates a new object that holds the text of the notification template
    NotificationTemplateTextInfo newText = new NotificationTemplateTextInfo();

    // Sets the text values for the template
    newText.TemplateSubject = "Template subject";                   
    newText.TemplateHTMLText = "Template text. <br />";
    newText.TemplatePlainText = "Template text.";

    // Assigns the text values to the template for the specified notification gateway
    newText.TemplateID = newTemplate.TemplateID;
    newText.GatewayID = gateway.GatewayID;

    // Saves the notification template text to the database
    NotificationTemplateTextInfoProvider.SetNotificationTemplateTextInfo(newText);
}

```

[> Back to list of examples](#notifications-toc)

### Updating a notification template

```csharp

// Gets the notification template
NotificationTemplateInfo updateTemplate = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("NewTemplate", SiteContext.CurrentSiteID);
if (updateTemplate != null)
{
    // Updates the basic notification template properties
    updateTemplate.TemplateDisplayName = updateTemplate.TemplateDisplayName.ToLowerCSafe();

    // Saves the modified notification template to the database
    NotificationTemplateInfoProvider.SetNotificationTemplateInfo(updateTemplate);

    // Gets a notification gateway
    NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("NewGateway");

    if (gateway != null)
    {
        // Gets the object holding the template's text for the specified notification gateway
        NotificationTemplateTextInfo updateText = NotificationTemplateTextInfoProvider
                                                    .GetNotificationTemplateTextInfo(gateway.GatewayID, updateTemplate.TemplateID);

        if (updateText != null)
        {
            // Updates the template's subject text for the specified gateway
            updateText.TemplateSubject = updateText.TemplateSubject.ToLowerCSafe();

            // Saves the modified notification template text to the database
            NotificationTemplateTextInfoProvider.SetNotificationTemplateTextInfo(updateText);                           
        }
    }
}

```

[> Back to list of examples](#notifications-toc)

### Updating multiple notification templates

```csharp

// Gets all notification templates assigned to the current site whose code name starts with 'New'
var templates = NotificationTemplateInfoProvider.GetNotificationTemplates()
                                                .WhereStartsWith("TemplateName", "New")
                                                .WhereEquals("TemplateSiteID", SiteContext.CurrentSiteID);

// Loops through individual notification templates
foreach (NotificationTemplateInfo template in templates)
{
    // Updates the basic notification template properties
    template.TemplateDisplayName = template.TemplateDisplayName.ToUpper();

    // Saves the modified notification template to the database
    NotificationTemplateInfoProvider.SetNotificationTemplateInfo(template);

    // Gets all template text objects that belong to the given template (for all notification gateways)
    var templateTexts = NotificationTemplateTextInfoProvider.GetNotificationTemplateTexts().WhereEquals("TemplateID", template.TemplateID);

    // Loops through the template's text objects for all gateways
    foreach (NotificationTemplateTextInfo templateText in templateTexts)
    {
        // Updates the template's subject text
        templateText.TemplateSubject = templateText.TemplateSubject.ToUpper();

        // Saves the modified notification template text to the database
        NotificationTemplateTextInfoProvider.SetNotificationTemplateTextInfo(templateText);
    }
}

```

[> Back to list of examples](#notifications-toc)

### Deleting a notification template

```csharp

// Gets the notification template
NotificationTemplateInfo deleteTemplate = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("NewTemplate", SiteContext.CurrentSiteID);

if (deleteTemplate != null)
{
    // Gets all template text objects that belong to the given template (for all notification gateways)
    var templateTexts = NotificationTemplateTextInfoProvider.GetNotificationTemplateTexts().WhereEquals("TemplateID", deleteTemplate.TemplateID);

    // Loops through the template's text objects for all gateways
    foreach (NotificationTemplateTextInfo deleteText in templateTexts)
    {
        // Deletes the notification template's text
        NotificationTemplateTextInfoProvider.DeleteNotificationTemplateTextInfo(deleteText);
    }

    // Deletes the notification template
    NotificationTemplateInfoProvider.DeleteNotificationTemplateInfo(deleteTemplate);
}

```

[> Back to list of examples](#notifications-toc)

## Notification subscriptions

### Creating a notification subscription

```csharp

// Gets the notification gateway
NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("NewGateway");

// Get the notification template
NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("NewTemplate", SiteContext.CurrentSiteID);

if ((gateway != null) && (template != null))
{
    // Creates a new notification subscription object
    NotificationSubscriptionInfo newSubscription = new NotificationSubscriptionInfo();

    // Sets the subscription properties (subscribes the current user)
    newSubscription.SubscriptionEventDisplayName = "Custom event";
    newSubscription.SubscriptionGatewayID = gateway.GatewayID;
    newSubscription.SubscriptionTemplateID = template.TemplateID;
    newSubscription.SubscriptionTime = DateTime.Now;
    newSubscription.SubscriptionUserID = MembershipContext.AuthenticatedUser.UserID;
    newSubscription.SubscriptionTarget = MembershipContext.AuthenticatedUser.Email;
    newSubscription.SubscriptionSiteID = SiteContext.CurrentSiteID;

    // Saves the notification subscription to the database
    NotificationSubscriptionInfoProvider.SetNotificationSubscriptionInfo(newSubscription);
}

```

[> Back to list of examples](#notifications-toc)

### Updating notification subscriptions

```csharp

// Gets the notification gateway
NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("NewGateway");

// Gets the notification template
NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("NewTemplate", SiteContext.CurrentSiteID);

if ((gateway != null) && (template != null))
{
    // Gets all subscriptions that use the specified notification gateway and template
    var subscriptions = NotificationSubscriptionInfoProvider.GetNotificationSubscriptions()
                                                            .WhereEquals("SubscriptionGatewayID", gateway.GatewayID)
                                                            .WhereEquals("SubscriptionTemplateID", template.TemplateID);

    // Loops throug individual subscriptions
    foreach (NotificationSubscriptionInfo subscription in subscriptions)                    
    {
        // Updates the subscription properties
        subscription.SubscriptionEventDisplayName = subscription.SubscriptionEventDisplayName.ToLowerCSafe();

        // Saves the updated notification subscription to the database
        NotificationSubscriptionInfoProvider.SetNotificationSubscriptionInfo(subscription);
    }
}

```

[> Back to list of examples](#notifications-toc)

### Deleting notification subscriptions

```csharp

// Gets the notification gateway
NotificationGatewayInfo gateway = NotificationGatewayInfoProvider.GetNotificationGatewayInfo("NewGateway");

// Gets the notification template
NotificationTemplateInfo template = NotificationTemplateInfoProvider.GetNotificationTemplateInfo("NewTemplate", SiteContext.CurrentSiteID);

if ((gateway != null) && (template != null))
{
    // Gets all subscriptions that use the specified notification gateway and template
    var subscriptions = NotificationSubscriptionInfoProvider.GetNotificationSubscriptions()
                                                            .WhereEquals("SubscriptionGatewayID", gateway.GatewayID)
                                                            .WhereEquals("SubscriptionTemplateID", template.TemplateID);

    // Loops throug individual subscriptions
    foreach (NotificationSubscriptionInfo deleteSubscription in subscriptions)
    {
        // Deletes the notification subscription
        NotificationSubscriptionInfoProvider.DeleteNotificationSubscriptionInfo(deleteSubscription);
    }
}

```

[> Back to list of examples](#notifications-toc)
