Email mailing lists
A mailing list is a set of subscribers. For example, subscribers that are interested in new forum posts in a forum thread, can form a subscription list for the forum thread. You can use the ISubscriptionListRequestinterface to represent a subscription list. The provided SubscriptionListRequestProxy class implements the interface.
Creating a subscription list and adding a new subscriber to it
The following example shows how to create a subscription list and add new subscriber to it:
C#
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Notifications;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.NotificationService
{
public partial class NotificationServiceSnippets
{
public static void CreateSubscriptionListAndAddSubscriber()
{
var context = new ServiceContext("myNotificationAccount", "MyCustomModule");
var ns = SystemManager.GetNotificationService();
ISubscriberRequest subscriber = new SubscriberRequestProxy()
{
Email = "test.subscriber@company.com",
FirstName = "First",
LastName = "Last",
ResolveKey = "unique-identifier-in-the-specified-context"
};
ISubscriptionListRequest subscriptionList = new SubscriptionListRequestProxy()
{
Title = "SampleList",
ResolveKey = "unique-identifier-in-the-specified-context",
Description = "Sample subscirption lsit description."
};
//Persisting the subscription list
var subscriptionListId = ns.CreateSubscriptionList(context, subscriptionList);
ns.Subscribe(context, subscriptionListId, subscriber);
}
}
}
Adding an existing subscriber to an existing mailing list, using ID
For adding an existing subscriber to an existing mailing list using ID, see example below:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Notifications;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.NotificationService
{
public partial class NotificationServiceSnippets
{
public static void AddSubscriberToSubscribtionListById()
{
var context = new ServiceContext("myNotificationAccount", "MyCustomModule");
var ns = SystemManager.GetNotificationService();
//Id of an existing subscription list
Guid subscriptionListId = Guid.Empty;
//Id of an existing subscriber
Guid subscriberId = Guid.Empty;
ns.Subscribe(context, subscriptionListId, subscriberId);
}
}
}
Adding an existing subscriber to an existing mailing list using ResolveKey
The sample below demonstrates how to add an existing subscriber to an existing mailing list using ResolveKey:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Notifications;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.NotificationService
{
public partial class NotificationServiceSnippets
{
public static void AddSubscriberToListByResolveKey()
{
var context = new ServiceContext("myNotificationAccount", "MyCustomModule");
var ns = SystemManager.GetNotificationService();
//Id of an existing subscription list
var subscriptionListId = Guid.Empty;
//Resolve key of an existing subscriber
string subscriberResolveKey = "unique-identifier-in-the-specified-context";
ns.Subscribe(context, subscriptionListId, subscriberResolveKey);
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.