Note! You are looking at documentation for an old version of the package. Go here for the latest documentation.

To interact with Newsletter Studio from the front end we provide a very simple API in the static class NewsletterStudio.Api. This class has several methods for adding and removing subscribers both from the built in subscriptions and from Umbraco's member section (it won't delete anything but it changes property values).

 

Api -developer -section


public static bool IsValidEmail(string email)
Helper that checks if a string contains a valid e-mail address

public static bool Subscribe(string email)
Adds a subscriber with only email to the default mailing list

public static bool Subscribe(string email, string name)
Adds a subscriber with email and name to the default mailing list.

public static bool Subscribe(string email, int mailinglistId)
Adds a subscriber with only email to a given mailing list. Works only with the default mailing lists in Newsletter Studio.

public static bool Subscribe(string email, string name, int mailinglistId)
Adds a new subscriber to a given mailing list. Works only with the default mailing lists in Newsletter Studio.

public static bool UnSubscribe(string email, string subscriptionAlias)
Unsubscribe an email from a given mailing list based on the subscription alias.

The subscription alias is build up using:
1. The unique name of the provider and
2. The data provider key for the list item.

Example: "NewsletterStudioSubscriptionProvider_1" would be the Newsletter Studio Subscription Provider (for built in Mailing Lists) and the list with id 1. Have a look in the "newsletter" table in the database to see more examples of subscription aliases.

NOTE: Passing an empty string as subscriptionAlias will unsubscribe the email from all lists in all providers.

public static bool UnSubscribe(string email)
(Only in versions about 2.1.9.8) Unsubscribe an email from all lists in all Subscription Providers.

Examples

// Add to first list
NewsletterStudio.Api.Subscribe("email@site.com");

// Add to specific list (by id)
NewsletterStudio.Api.Subscribe("email@site.com",7);

// Add to specific list, set name
NewsletterStudio.Api.Subscribe("email@site.com","John Doe",3);

// Unsubscribe from MailingList with id 1
NewsletterStudio.Api.UnSubscribe("email@site.com", "NewsletterStudioSubscriptionProvider_1");

// Unsubscribe from ALL lists (passing empty string as subscriptionAlias)
NewsletterStudio.Api.UnSubscribe("email@site.com", "");

 




More articles on "Develop with Newsletter Studio"

Control content with Render Tasks

Using a render task an developer can hook into the rendering process of the email and make changes to the message body/subject. This can be done both on an overall level and on each individual email (ie. personalization). This feature could for example be used to replace [sometext] inside the messag…

Read article

Subscription Providers

Can be used to hook into other systems or data sources. Newsletter Studio will use the providers to fetch the needed information about the receivers. All current subscriptions options (Newsletter Studios native mailing list and Umbraco members) are build with providers and it's easy to implement you…

Read article

Events

Since version 1.4.5 and 2.1 Newletter Studio contains some events that you as a developer can use when you develop your solutions.  Event name v1.4.5+ v2.1+ NewsletterStudio.Services.SendNewsletterService.SendningInitializing Yes Yes NewsletterStudio.Services.SendNewsletterService.Sent Yes Ye…

Read article

Custom data fields

The default property fields for receivers in Newsletter Studio are: name, e-mail, subscribed date and status. But some clients want to add custom data to their contacts.Since version 2.1 we've decided to prepare the underlying data layer for this by adding a new property called “Data” on the Receive…

Read article

Working programmatically

There is a lot of things that can be done using the services and repositories that Newsletter Studio provides. You can explore these APIs using the "GlobalFactory" which is a service locator that the package uses internally. For example, you can access the Mailing List Repository like this: Newslett…

Read article