Querying subscribers

To retrieve all subscribers from a mailing list, you use the NewslettersManager class. The following code retrieves all subscribers from a mailing list with the specified Id through the Native API.

public List<Subscriber> QuerySubscribers( Guid mailingListId )
{
    List<Subscriber> subscribers = new List<Subscriber>();
 
    NewslettersManager manager = NewslettersManager.GetManager();
    MailingList mailingList = manager.GetMailingLists().Where( l => l.Id == mailingListId ).SingleOrDefault();
 
    if (mailingList != null)
    {
        subscribers = mailingList.Subscribers.ToList();
    }
 
    return subscribers;
}

First, you initialize the NewslettersManager. Then, you must call GetMailingLists to retrieve all mailing lists and filter them based on the Idproperty. Then, you check whether a mailing list with the specified ID exists. Finally, you get all subscribers from the mailing list and return them as a result.

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