Creating subscribers

To create a subscriber, you use the NewslettersManager class. The following code creates a subscriber and adds it to the specified mailing list through the Native API.

public void AddSubscribersToMailingList(Guid subscriberId, Guid mailingListId, string firstName, string lastName, string email)
{
    NewslettersManager manager = NewslettersManager.GetManager();
    MailingList mailingList = manager.GetMailingLists().Where(l => l.Id == mailingListId).SingleOrDefault();
 
    if (mailingList != null)
    {
        Subscriber subscriber = manager.CreateSubscriber(false, subscriberId);
        subscriber.FirstName = firstName;
        subscriber.LastName = lastName;
        subscriber.Email = email;
 
        manager.Subscribe(subscriber, mailingListId);
        manager.SaveChanges();
    }
}

First, you initialize the NewslettersManager. Then, you get the specified mailing list. You call the CreateSubscriber method to create the subscriber and then you set its properties. Then, you call the Subscribe method to add the subscriber to the mailing list. Finally, you save the changes.

See Also

Other Resources

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