More in this section

Forums / Developing with Sitefinity / NewsLetter recipients at runtime from other datasource

NewsLetter recipients at runtime from other datasource

2 posts, 0 answered
  1. Panos Klaoudatos
    Panos Klaoudatos avatar
    8 posts
    14 Aug 2012
    29 May 2009
    Link to this post

    I am interested in building an alternative control/template for the newsletter, so that I can send it to a number of users that are grouped at runtime.

    For example, let's say we have a second membership provider with some customers associated with it. At some time, I want to send a newsletter (or a notification letter for that matter) to these customers. I want to be able to select the customers from my database (via the membership provider), based on some custom filter (e.g. those that they have a payment overdue - utilizing a dropdownlist). I don't just want to select them from a subscribers group.
    The reason for the latter, is that when a customer makes the payment and it's no longer overdue, the custom filter will not select him. If on the other hand this customer was in a subscribers group, I would have to unsubscribe him manually first and then send the newsletter.

    Is the above possible? Can you give me some hints on newsletter module or C# code on how to inherit and override the newsletter module so that it has such a functionality?
  2. Parvan
    Parvan avatar
    151 posts
    24 Sep 2012
    30 May 2009
    Link to this post
    Hello Panos Klaoudatos,

    Thank you for using our services.

    You have full control of managing subscribers, groups, newsletters by using the Telerik.Notifications.Newsletters.DataManager class.
    Here is an example how to collect the users from the membership provider and send a newsletter to them:
    using Telerik.Notifications.Newsletters; 
    using Telerik.Newsletters; 
    using System.Collections.Generic; 
    using System.Collections; 
    using System.Web.Security; 
    void sendMails() 
            DataManager dataManager; 
            dataManager = new DataManager(); 
            IList newsletters; 
            newsletters = dataManager.GetNewsletters(); 
            if (newsletters.Count == 0) 
            //Find the newsletter with the specified subject 
            INewsletter selectedNewsletter = newsletters[0] as INewsletter; 
            if (selectedNewsletter != null
                //Fill the subscribers to which to send the newsletter 
                List<string> subscribers = new List<string>(); 
                IList groupsOfNewsletter; 
                groupsOfNewsletter = dataManager.GetGroupOfNewsletter(selectedNewsletter.NewsletterId); 
                /* //This is an example how to iterate through the Subscribers collection
                 * foreach (IGroup group in groupsOfNewsletter)
                    foreach (IGroupSubscriber subscriber in @group.Subscribers)
                MembershipProvider provider = Membership.Provider; 
                int total; 
                MembershipUserCollection allUsers = provider.GetAllUsers(0,100,out total); 
                foreach (MembershipUser user in allUsers) 
                    if (true// Filter here users 
                string[] toList = subscribers.ToArray(); 
                NewsletterManager.SendEmailAsync(toList, selectedNewsletter.Content, selectedNewsletter.Subject, selectedNewsletter.SenderName, selectedNewsletter.SenderName); 

    This will work even if you use this sample in your user control).

    If you want you can use the admin templates located in the ~\Sitefinity\Admin\ControlTemplates\Notifications\ directory. It depends on the user interface you would like to have. You may need to override new Newsletter module classes - I have attached you an start example how to override the ControlPanel and CommandPanel. 
    1. Put the files in App_Code folder
    2. Edit your web.config file (change the green with the yellow):
       <add type="Telerik.Notifications.Newsletters.NewsletterModule, Telerik.Notifications"/> 

      <add type="CustomNewslettersModule, App_Code"/> 

    Also you can read more about architecture of modules in Sitefinity - Outline documentation for 3.6,   Bare-bones Pluggable Module - Explained.

    I hope this information will help you.

    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
2 posts, 0 answered