Create message templates

To create a message template, you must use the NewslattersManager class. First, you initialize the NewslettersManager. Then, you call CreateMessageBody to create a message template. Finally, after all properties are set, you save the changes.

The following code creates a message template with specific ID, Name, BodyText, and MessageBodyTypewith the Native API:

  1. C#
     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;
     using System.Threading.Tasks;
     using Telerik.Sitefinity.Modules.Newsletters;
     using Telerik.Sitefinity.Newsletters.Model;
     
     namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.EmailCampaigns
     {
         public partial class EmailCampaignsSnippets
         {
             public void CreateMessageBody(Guid id, string name, MessageBodyType bodyType, string bodyText, bool isTemplate)
             {
                 NewslettersManager manager = NewslettersManager.GetManager();
                 MessageBody messageBody = manager.GetMessageBodies().Where(b => b.Id == id).SingleOrDefault();
     
                 if (messageBody == null)
                 {
                     messageBody = manager.CreateMessageBody(id);
                     messageBody.Name = name;
                     messageBody.MessageBodyType = bodyType;
                     messageBody.BodyText = bodyText;
                     messageBody.IsTemplate = isTemplate;
                     manager.SaveChanges();
                 }
             }
         }
     }
     

NOTE: To create a campaign with auto-generated ID, use the other overload of the CreateMessageBody method.
To indicate that the message body must be used as a template, you must set the IsTemplate property to true.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?