Adding subscribers to mailing list

To add a specific subscriber to a list, you use the NewslettersManager class. The following code adds the specified subscriber to the specified mailing list through the Native API.

public void AddSubscriberToMailingList(Guid subscriberId, Guid mailingListId)
{
    NewslettersManager manager = NewslettersManager.GetManager();
    MailingList mailingList = manager.GetMailingLists().Where(l => l.Id == mailingListId).SingleOrDefault();
 
    if (mailingList != null)
    {
        Subscriber subscriber = manager.GetSubscribers().Where(s => s.Id == subscriberId).SingleOrDefault();
        if (!mailingList.Subscribers.Contains(subscriber))
        {
            manager.Subscribe(subscriber, mailingListId);
        }
 
        manager.SaveChanges();
    }
}

First, you initialize the NewslettersManager. Then, you get the specified mailing list. If the list exists, you get the specified subscriber and add him/her to the mailing list. Finally, you save the changes.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK