The following example creates a subscription template.
privatevoid CreateSubscriptionTemplate() { // Creates a new subscription template object EmailTemplateInfo newTemplate = newEmailTemplateInfo();
// Sets the properties newTemplate.TemplateDisplayName = "My new subscription template"; newTemplate.TemplateName = "MyNewSubscriptionTemplate"; newTemplate.TemplateType = EmailTemplateType.Subscription; newTemplate.TemplateBody = "My new subscription template body"; newTemplate.TemplateHeader = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Newsletter</title><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /></head><body>"; newTemplate.TemplateFooter = "</body></html>"; newTemplate.TemplateSiteID = CMSContext.CurrentSiteID;
// Saves the subscription template EmailTemplateInfoProvider.SetEmailTemplateInfo(newTemplate); }
The following example creates an unsubscription template.
privatevoid CreateUnsubscriptionTemplate() { // Creates a new unsubscription template object EmailTemplateInfo newTemplate = newEmailTemplateInfo();
// Sets the properties newTemplate.TemplateDisplayName = "My new unsubscription template"; newTemplate.TemplateName = "MyNewUnsubscriptionTemplate"; newTemplate.TemplateType = EmailTemplateType.Unsubscription; newTemplate.TemplateBody = "My new unsubscription template body"; newTemplate.TemplateHeader = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Newsletter</title><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /></head><body>"; newTemplate.TemplateFooter = "</body></html>"; newTemplate.TemplateSiteID = CMSContext.CurrentSiteID;
// Saves the unsubscription template EmailTemplateInfoProvider.SetEmailTemplateInfo(newTemplate); }
The following example creates an issue template.
privatevoid CreateIssueTemplate() { // Creates a new issue template object EmailTemplateInfo newTemplate = newEmailTemplateInfo();
// Sets the properties newTemplate.TemplateDisplayName = "My new issue template"; newTemplate.TemplateName = "MyNewIssueTemplate"; newTemplate.TemplateType = EmailTemplateType.Issue; newTemplate.TemplateBody = "<p>My new issue template body</p><p>$$content:800:600$$</p>"; newTemplate.TemplateHeader = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Newsletter< title><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /></head><body>"; newTemplate.TemplateFooter = "</body></html>"; newTemplate.TemplateSiteID = CMSContext.CurrentSiteID;
// Saves the issue template EmailTemplateInfoProvider.SetEmailTemplateInfo(newTemplate); }
The following example gets and updates an issue template.
privatebool GetAndUpdateIssueTemplate() { // Gets the issue template EmailTemplateInfo updateTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo("MyNewIssueTemplate", CMSContext.CurrentSiteID); if (updateTemplate != null) { // Updates the properties updateTemplate.TemplateDisplayName = updateTemplate.TemplateDisplayName.ToLower();
// Saves the changes EmailTemplateInfoProvider.SetEmailTemplateInfo(updateTemplate);
returntrue; }
returnfalse; }
The following example gets and bulk updates issue templates.
privatebool GetAndBulkUpdateIssueTemplates() { // Prepares the parameters string where = "TemplateName LIKE N'MyNewIssueTemplate%'";
// Gets the data DataSet templates = EmailTemplateInfoProvider.GetEmailTemplates(where, null); if (!DataHelper.DataSourceIsEmpty(templates)) { // Loops through individual items foreach (DataRow templateDr in templates.Tables[0].Rows) { // Creates an object from the DataRow EmailTemplateInfo modifyTemplate = newEmailTemplateInfo(templateDr);
// Updates the properties modifyTemplate.TemplateDisplayName = modifyTemplate.TemplateDisplayName.ToUpper();
// Saves the changes EmailTemplateInfoProvider.SetEmailTemplateInfo(modifyTemplate); }
returntrue; }
returnfalse; }
The following example deletes a subscription template.