More in this section

Forums / Developing with Sitefinity / Create a Newsletter programatically

Create a Newsletter programatically

2 posts, 0 answered
  1. Carlos Souto
    Carlos Souto avatar
    6 posts
    Registered:
    09 Jul 2009
    16 Nov 2009
    Link to this post
    Hello guys!

    What is the correct way to create and send a newsletter programatically?

    As there is no (explicit) Newsletter API documentation, i am trying with code blocks i found in the Telerik foruns, like this:

                DataManager manager = new DataManager();
                IGroup advisoryGroup = manager.GetGroup(new Guid("6fdd6de5-4f0f-4836-9421-de91db1f4aa4"));

                int count = advisoryGroup.Subscribers.Count;
                List<string> subscribers = new List<string>();

                for (int i = 0; i < count; i++)
                {
                    subscribers.Add(advisoryGroup.Subscribers[i].ToString());
                }

                //Create the Newsletter content:
                //INewsletter news = manager.CreateNewsletter(); // <- First non successful attempt
                Telerik.Notifications.Data.Newsletter news = new Telerik.Notifications.Data.Newsletter();
                //news.Groups = ;
                news.Content = "body of newsletter";
                news.DateCreated = DateTime.Now;
                news.Subject = "Advisory Manager";            
                
                //Send the new newsletter to subscribers:
                manager.SaveNewsletter(news);

                NewsletterManager.SendEmailAsync(subscribers.ToArray(), news.Content, news.Subject, news.SenderName, news.SenderMail);

    Also, could you please let me know if is there any way to attach a file to the newsletter or wich object am i supposed to extend to allw for this feature.

    Best Regards

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 Nov 2009
    Link to this post
    Hello Carlos Souto,

    You can use NewsletterManager.SendEmail method. You could also try to use SendEmailsWithDBUpdaingAsync method.

    DataManager dm = new DataManager();
        IList subscribers = dm.GetSubscribers();
        foreach (Telerik.Newsletters.ISubscriber subscriber in subscribers)
        {
            string[] toList = new string[] { subscriber.Email };
            string body = "SOME BODY HERE";
            string subject = "SUBJECT";
            string senderName = "SENDER NAME";
            string senderAddress = "SENDER ADDRESS";
            NewsletterManager.SendEmail(toList, body, subject, senderName, senderAddress);
        }

    Unfortunately the current implementation does not support using attachments. The easiest way for using attachments will be using MailMessage ASP.NET class

    MailMessage msgMail = new MailMessage();
    msgMail.Attachments.Add(Item);

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered