How to Include an RSS Feed in an Email Message using AMPscript

From $1

    This document contains conceptual, procedural and scenario information about including RSS feeds in the content of an email message. You can use AMPscript to pull content from an RSS feed and put that content into an email message

    Prerequisites

    You must be familiar with the email creation process and AMPscript before attempting to use the information in this document. Your RSS feed must also be operational and published to the Internet before you can use it in an email.

    Why Include an RSS Feed in an Email Message

    RSS presents an XML-based list that showcase the latest articles published on a website or other RSS-enabled content source. You can use AMPscript to take the information from an RSS feed during the send to make sure you include the most current information possible in your email send.

    Scenario

    Northern Trail Outfitters maintains a blog for several key employees to use in sharing their experiences with Northern Trail equipment and the outdoors. They also send out a weekly email newsletter, and they'd like to include links to the latest blog entries as part of the newsletter. They use AMPscript to pull the RSS feeds into the email at the time of send.

    Procedures

    Follow the procedures below to include an RSS feed in your email sends.

    How to Include an RSS Feed in an Email Message

    1. Create a content area that uses the HTML Only orientation in your account.
    2. Include the following content syndication link in that content area: %%before; httpget; 1 "INSERT URL HERE"%%
    3. Note the name of the content area containing the content syndication link. In this case, the content area is named RSSParse, and you can find it in my contents\RSSParse\RSSParse. This is a separate content area from the content area you will include in the email message - the AMPscript pulls the content from the RSSParse content area and puts it in the content area contained in the email message.
    4. In the email message's content area, include the AMPscript shown below:
      %%[Var @xml, @titles, @title, @descs, @desc, @links, @link, @cnt
      Set @xml = ContentAreaByName("my contents\RSSParse\RSSParse") //This line specifies the content area from which the RSS content will be pulled for the email message. 
      Set @titles = BuildRowsetFromXML(@xml,"//item/title",1)
      Set @descs = BuildRowsetFromXML(@xml,"//item/description",1)
      Set @links = BuildRowsetFromXML(@xml,"//item/link",1)
      
      If RowCount(@titles) > 5 THEN
      SET @rows = 5
      ELSE
      SET @rows = RowCount(@titles)
      ENDIF
      
      IF @rows >= 1 THEN
      for @cnt = 1 to 5 do
      Set @title = Field(Row(@titles,@cnt),"Value")
      Set @desc = Field(Row(@descs,@cnt), "Value")
      Set @link = Field(Row(@links,@cnt), "Value") ]%%
      
      <div style="border: 1px solid #444; background-color: #F7F7F7; margin: 0.76em 0; padding: 0.76em;">
      <h1 style="font: bold normal 1.0em Arial, Helvetica, sans-serif;"><a href="%%=RedirectTo(@link)=%%" alias="%%=v(@title)="%%" title="%%=v(@title)=%% style="color: #000;">%%=v(@title)=%%</a></h1>
      <span style="font: normal normal 0.76em Arial, Helvetica, sans-serif; color: #444;">%%=v(@desc)=%%</span>
      </div>
      %%[ 
      NEXT @cnt 
      ENDIF
      ]%%
    5. Test the email before sending to make sure the message pulls the correct content.

    In the AMPscript listed above, the AMPscript takes the most recent 5 entries from the feed and includes them in the email. The @xml variable pull in the content area with the content syndication, while the other variables pull information from the feed to include in the email. The For loop in the email counts how many times articles have been pulled from the feed and stops the message at 5.

    You can modify the HTML markup included in the example to better fit the formatting of your email message.

    NOTE: If the RSS Feed pulled into the email contains HTML formatting, be sure to clear the text version of any AMPscript and provide the VAWP URL as a mechanism to view the email. If you do not do this, the email send will fail.

    If you reference a node that includes a colon, the parser will not accept that colon and cause the operation to error out. Use the sample code below as an example to get around the colon and successfully add your RSS feed:

    %%[Var @xml, @xml1, @titles, @title, @descs, @desc, @links, @link, @cnt
    Set @xml1 = ContentAreaByName("my contents\RSSParse\RSSParse") //This line specifies the content area from which the RSS content will be pulled for the email message. 
    Set @xml = Replace(@xml1,'content:encoded','contentencoded')
    Set @titles = BuildRowsetFromXML(@xml,"//item/title",1)
    Set @descs = BuildRowsetFromXML(@xml,"//item/contentencoded",1)
    Set @links = BuildRowsetFromXML(@xml,"//item/link",1)
    
    If RowCount(@titles) > 5 THEN
    SET @rows = 5
    ELSE
    SET @rows = RowCount(@titles)
    ENDIF
    
    IF @rows >= 1 THEN
    for @cnt = 1 to 5 do
    Set @title = Field(Row(@titles,@cnt),"Value")
    Set @desc = Field(Row(@descs,@cnt), "Value")
    Set @link = Field(Row(@links,@cnt), "Value") ]%%
    
    <div style="border: 1px solid #444; background-color: #F7F7F7; margin: 0.76em 0; padding: 0.76em;">
    <h1 style="font: bold normal 1.0em Arial, Helvetica, sans-serif;"><a href="%%=RedirectTo(@link)=%%" alias="%%=v(@title)="%%" title="%%=v(@title)=%% style="color: #000;">%%=v(@title)=%%</a></h1>
    <span style="font: normal normal 0.76em Arial, Helvetica, sans-serif; color: #444;">%%=v(@desc)=%%</span>
    </div>
    %%[ 
    NEXT @cnt 
    ENDIF
    ]%%

    This page was last updated by Ryan Williams on Tue, 16 Aug 2011 12:51:18 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 14570 backwards:
       
    Tags: (Edit tags)
    • No tags
     
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin