Removing subscribers from a mailing list
To remove a specific subscriber from a list, you use the NewslettersManager class. The following code removes the specified subscriber through the Native API.
public void RemoveSubscriberFromMailingList(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 (subscriber.Lists.Contains(mailingList))
{
manager.Unsubscribe(subscriber, mailingList.Id);
}
manager.SaveChanges();
}
}
First, you initialize the NewslettersManager. Then, you get the specified mailing list. If the list exists, you get the specified subscriber and unsubscribe him/her by calling the Unsubscribe method of the NewslettersManager class. Finally, you save the changes.