Kentico CMS 7.0 Developer's Guide

Managing newsletters

Managing newsletters

Previous topic Next topic Mail us feedback on this topic!  

Managing newsletters

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a static newsletter.

 

private bool CreateStaticNewsletter()
{
  EmailTemplateInfo subscriptionTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo("MyNewSubscriptionTemplate", CMSContext.CurrentSiteID);
  EmailTemplateInfo unsubscriptionTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo("MyNewUnsubscriptionTemplate", CMSContext.CurrentSiteID);
  EmailTemplateInfo myNewIssueTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo("MyNewIssueTemplate", CMSContext.CurrentSiteID);

 
  if ((subscriptionTemplate != null) && (unsubscriptionTemplate != null) && (myNewIssueTemplate != null))
   {
      // Creates a new static newsletter object
      NewsletterInfo newNewsletter = new NewsletterInfo();

 
      // Sets the properties
       newNewsletter.NewsletterDisplayName = "My new static newsletter";
       newNewsletter.NewsletterName = "MyNewStaticNewsletter";
       newNewsletter.NewsletterType = NewsletterType.TemplateBased;
       newNewsletter.NewsletterSubscriptionTemplateID = subscriptionTemplate.TemplateID;
       newNewsletter.NewsletterUnsubscriptionTemplateID = unsubscriptionTemplate.TemplateID;
       newNewsletter.NewsletterTemplateID = myNewIssueTemplate.TemplateID;
       newNewsletter.NewsletterSenderName = "Sender name";
       newNewsletter.NewsletterSenderEmail = "sender@localhost.local";
       newNewsletter.NewsletterSiteID = CMSContext.CurrentSiteID;

 
      // Saves the static newsletter
      NewsletterInfoProvider.SetNewsletterInfo(newNewsletter);

 
      return true;
   }

 
  return false;
}

 

The following example gets and updates a static newsletter.

 

private bool GetAndUpdateStaticNewsletter()
{
  // Gets the static newsletter
  NewsletterInfo updateNewsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewStaticNewsletter", CMSContext.CurrentSiteID);
  if (updateNewsletter != null)
   {
      // Updates the properties
       updateNewsletter.NewsletterDisplayName = updateNewsletter.NewsletterDisplayName.ToLower();

 
      // Saves the changes
      NewsletterInfoProvider.SetNewsletterInfo(updateNewsletter);

 
      return true;
   }

 
  return false;
}

 

The following example gets and bulk updates static newsletters.

 

private bool GetAndBulkUpdateStaticNewsletters()
{
  // Prepares the parameters
  string where = "NewsletterName LIKE N'MyNewStaticNewsletter%'";

 
  // Gets the data
  DataSet newsletters = NewsletterInfoProvider.GetNewsletters(where, null, 0, null);
  if (!DataHelper.DataSourceIsEmpty(newsletters))
   {
      // Loops through the items
      foreach (DataRow newsletterDr in newsletters.Tables[0].Rows)
       {
          // Creates an object from the DataRow
          NewsletterInfo modifyNewsletter = new NewsletterInfo(newsletterDr);

 
          // Updates the properties
           modifyNewsletter.NewsletterDisplayName = modifyNewsletter.NewsletterDisplayName.ToUpper();

 
          // Saves the changes
          NewsletterInfoProvider.SetNewsletterInfo(modifyNewsletter);
       }

 
      return true;
   }

 
  return false;
}

 

The following example creates a dynamic newsletter.

 

private bool CreateDynamicNewsletter()

{

  EmailTemplateInfo subscriptionTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo("MyNewSubscriptionTemplate", CMSContext.CurrentSiteID);

  EmailTemplateInfo unsubscriptionTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo("MyNewUnsubscriptionTemplate", CMSContext.CurrentSiteID);

 

  if ((subscriptionTemplate != null) && (unsubscriptionTemplate != null))

   {

      // Creates a new dynamic newsletter object

      NewsletterInfo newNewsletter = new NewsletterInfo();

 
      // Sets the properties
       newNewsletter.NewsletterDisplayName = "My new dynamic newsletter";
       newNewsletter.NewsletterName = "MyNewDynamicNewsletter";
       newNewsletter.NewsletterType = NewsletterType.Dynamic;
       newNewsletter.NewsletterSubscriptionTemplateID = subscriptionTemplate.TemplateID;
       newNewsletter.NewsletterUnsubscriptionTemplateID = unsubscriptionTemplate.TemplateID;
       newNewsletter.NewsletterSenderName = "Sender name";
       newNewsletter.NewsletterSenderEmail = "sender@localhost.local";
       newNewsletter.NewsletterDynamicURL = "http://www.google.com";
       newNewsletter.NewsletterDynamicSubject = "My new dynamic issue";
       newNewsletter.NewsletterSiteID = CMSContext.CurrentSiteID;

 
      // Saves the dynamic newsletter
      NewsletterInfoProvider.SetNewsletterInfo(newNewsletter);

 
      return true;
   }

 
  return false;
}

 

The following example gets and updates a dynamic newsletter.

 

private bool GetAndUpdateDynamicNewsletter()
{
  // Gets the dynamic newsletter
  NewsletterInfo updateNewsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", CMSContext.CurrentSiteID);
  if (updateNewsletter != null)
   {
      // Updates the properties
       updateNewsletter.NewsletterDisplayName = updateNewsletter.NewsletterDisplayName.ToLower();

 
      // Saves the changes
      NewsletterInfoProvider.SetNewsletterInfo(updateNewsletter);

 
      return true;
   }

 
  return false;
}

 

The following example gets and bulk updates dynamic newsletters.

 

private bool GetAndBulkUpdateDynamicNewsletters()
{
  // Prepares the parameters
  string where = "NewsletterName LIKE N'MyNewDynamicNewsletter%'";

 
  // Gets the data
  DataSet newsletters = NewsletterInfoProvider.GetNewsletters(where, null, 0, null);
  if (!DataHelper.DataSourceIsEmpty(newsletters))
   {
      // Loops through the items
      foreach (DataRow newsletterDr in newsletters.Tables[0].Rows)
       {
          // Creates an object from the DataRow
          NewsletterInfo modifyNewsletter = new NewsletterInfo(newsletterDr);

 
          // Updates the properties
           modifyNewsletter.NewsletterDisplayName = modifyNewsletter.NewsletterDisplayName.ToUpper();

 
          // Saves the changes
          NewsletterInfoProvider.SetNewsletterInfo(modifyNewsletter);
       }

 
      return true;
   }

 
  return false;
}

 

The following example deletes a dynamic newsletter.

 

private bool DeleteDynamicNewsletter()
{
  // Gets the dynamic newsletter
  NewsletterInfo deleteNewsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", CMSContext.CurrentSiteID);

 
  // Deletes the dynamic newsletter
  NewsletterInfoProvider.DeleteNewsletterInfo(deleteNewsletter);

 
  return (deleteNewsletter != null);

}

 

The following example deletes a static newsletter.

 

private bool DeleteStaticNewsletter()
{
  // Gets the static newsletter
  NewsletterInfo deleteNewsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewStaticNewsletter", CMSContext.CurrentSiteID);

 
  // Deletes the static newsletter
  NewsletterInfoProvider.DeleteNewsletterInfo(deleteNewsletter);

 
  return (deleteNewsletter != null);
}