More in this section

Forums / Developing with Sitefinity / Bulk adding emails to newsletters

Bulk adding emails to newsletters

2 posts, 0 answered
  1. Simon
    Simon avatar
    2 posts
    26 Jan 2009
    13 Feb 2009
    Link to this post

    Is there a way to add, for example, 1,000 emails in one go as subscribers to a newsletter?

    I can't currently see how to do this in the demo or documentation.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    13 Feb 2009
    Link to this post
    Hi Simon,

    Thank you for using our services.

    Here is my approach.

    First you need to create a file, let's say a cvs file with users email addresses. You can add first name, last name etc. Then you can create a use control that will parse the data from the cvs file.
    You should use CreateSubscriber method ( to create a new subscriber.
    Additionally you could also specify a Group where the users will be added.


    <asp:TextBox ID="absoluteURLtoCSV" runat="server"  
        Text="YOUR FILE HERE" Width="368px" /> 
    <br /><br /><br /><br /> 
    Choose a Subsciber Group in which to import users<p> 
    &nbsp;<asp:TextBox ID="subscriberGroupTextBox" runat="server"  
        Text="Subscriber Group" Width="368px" /> 
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="import" /> 

    code behind

        // set buffer size 
        public const int BUFFER_SIZE = 4096 ; 
        protected void Page_Load(object sender, EventArgs e) 
        protected void Button1_Click(object sender, EventArgs e) 
            // new instance of DataMAnager 
            DataManager dm = new DataManager(); 
            IGroup subscriberGroup = null ; 
            // get all groups          
            IList subscriberGroups = dm.GetGroups(""); 
            int i = 0; 
            // check whether the subscriber group exists. 
            while (subscriberGroup == null && i < subscriberGroups.Count) 
                // get the subscriber group value from the textbox 
                if (((IGroup)subscriberGroups[i]).GroupName == subscriberGroupTextBox.Text) 
                    subscriberGroup = (IGroup)subscriberGroups[i]; 
            if (subscriberGroup != null
                // get the cvs file 
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(absoluteURLtoCSV.Text); 
                HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); 
                // read the file 
                MemoryStream memoryStream = null
                byte[] buffer = new byte[BUFFER_SIZE]; 
                Stream responseStream = webResponse.GetResponseStream(); 
                    int readBytes; 
                    memoryStream = new MemoryStream(); 
                    while ((readBytes = responseStream.Read(buffer, 0, BUFFER_SIZE)) > 0) 
                        memoryStream.Write(buffer, 0, readBytes); 
                    string csvContents = 
                        Encoding.UTF8.GetString(memoryStream.GetBuffer(), 0, (int)memoryStream.Length); 
                    string[] subscribersRows = csvContents.Split('\n'); 
                    foreach (string subscriberRow in subscribersRows) 
                        string subscriberInfoRow = subscriberRow.Trim(); 
                        if (!string.IsNullOrEmpty(subscriberInfoRow)) 
                            string[] columns = subscriberInfoRow.Split(','); 
                            string userEmail = columns[0].Trim(); 
                          // create a new users here using CreateSubscriber method 
                            ISubscriber subscriber = dm.CreateSubscriber(userEmail); 
                            // get the first name from the cvs file
                            subscriber.FirstName = columns[1].Trim();
                            // get the last name from the cvs file
                            subscriber.LastName = columns[2].Trim(); 
                            IGroupSubscriber grSubs = 
                                dm.CreateGroupSubscriberRelation(subscriberGroup.GroupId, subscriber.SubscriberId); 
                    if (memoryStream != null
                Response.Write(string.Format("The subscriber group {0} does not exist!", subscriberGroupTextBox.Text)); 

    I hope this helps.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered