How to Display Email Campaign Issues on Sitefinity Pages

How to Display Email Campaign Issues on Sitefinity Pages

April 22, 2013 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

In this blog post I'm going to show you how to place links to already sent Email campaign issues on your Sitefinity pages. The same approach can be used to link fallback versions of your campaigns, directly in the issue itself.

To achieve this, we need two simple user controls:

  • NewsLettersFront contains a repeater that lists all your issues. Since all Sitefinity newsletters campaigns have internal links, that aren't visible if you're not logged it, you don't have a link for each issue as there used to be in 5.1. This functionality is removed, because of security reasons. What we'll do is render the content of the issue on a Sitefinity page, which will simulate the issue being opened in the browser. The repeater lists anchor items with URLs, leading to some page, concatenated with a queryString, where we pass the id of the issue. As I mentioned, you pass the issue id in the queryString and you're redirected to some page. Then on this page you have the CampaignDetail widget.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NewsLettersFront.ascx.cs" Inherits="SitefinityWebApp.NewsLettersFront" %>
 
<asp:Repeater runat="server" ID="myRep">
    <HeaderTemplate>
        <div class="span11">
            <div class="quotestests">
    </HeaderTemplate>
    <ItemTemplate>
           <a href='<%# string.Format("nameOfPageForIssues?id={0}", Eval("Id")) %>' ><%#Eval("Name")%></a>
        <br />
    </ItemTemplate>
    <FooterTemplate>
            </div>
        </div>
    </FooterTemplate>
 
</asp:Repeater>

code-behind
namespace SitefinityWebApp
{
    public partial class NewsLettersFront : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var pManager = PageManager.GetManager();
            using (ElevatedModeRegion elevatedModeRegion = new ElevatedModeRegion(pManager))
            {
 
                NewslettersManager manager = NewslettersManager.GetManager();
                Campaign campaign = manager.GetCampaigns().Where(c => c.Name == "TestCampaign").SingleOrDefault();
                var issues = manager.GetIssues(campaign);
                var render = new InMemoryPageRender();
 
 
                myRep.DataSource = issues;
                myRep.DataBind();
 
            }
 
        }
 
    }
}


  • CampaignDetail handles the logic for getting the queryString parameter value and using it to retrieve the issue. I'm retrieving the issue by its id with the GetIssue() method of the NewslettersManager. After you have the issue, you get its html, and with ResponseWrite (passing the html) you recreate the issue on the page. This way it looks like you're opening the issue in a new page:
public partial class CampaignDetail : System.Web.UI.UserControl
   {
       protected void Page_Load(object sender, EventArgs e)
       {
           var pManager = PageManager.GetManager();
           NewslettersManager newsletterManager = NewslettersManager.GetManager();
           var render = new InMemoryPageRender();
           var queryStringId = Request.QueryString["id"];
           if (queryStringId != null)
           {
               Campaign issue = newsletterManager.GetIssue(new Guid(queryStringId));
               if (issue != null)
               {
 
                   var campaignMessageBody = issue.MessageBody;
                   var node = pManager.GetPageNode(campaignMessageBody.Id);
                   var text = render.RenderPage(node, false, isIndexMode: false);
                   var realHtml = HtmlProcessor.ProcessHtml(text);
 
                   Response.Write(realHtml);
                   Response.Write("<br/>");
               }
           }
 
       }
   }

As mentioned above, you can use this approach to place fallback campaign links directly on the emails, sent to your subscribers.

Hope you find the blog post useful!
progress-logo

The Progress Guys

View all posts from The Progress Guys on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments
Comments are disabled in preview mode.
Topics
 
 
Latest Stories in
Your Inbox
Subscribe
More From Progress
d12fcc0bdb669b804e7f71198c9619a7
5 Questions Automakers Should Ask to Improve Asset Uptime
Download Whitepaper
 
SF_MQ_WCM
2018 Gartner Magic Quadrant Web Content Management (WCM)
Download Whitepaper
 
What-Serverless-Means-For-Enterprice-Apps-Kinvey
What Serverless Means for Enterprise Apps
Watch Webinar