Knowledge Base/ExactTarget Tips and Tricks/Developer's Forum

Automated Blog Syndication

Josiah Kaiser
posted this on August 31, 2009 05:20 pm

 

Things you need before we begin:

  1. URL of your blog's RSS/XML feed
  2. Programs and AIM enabled on your account

 

How it works:

 

Everyday a program runs that checks your blog for new posts. If a new post is found, then an email is sent to your list using content generated from your blog post. If no new posts are found, then no email is sent..

 

Set-up:

 

  1. First create a content area. Choose HTML only as the type. In the content area insert the following code replacing the bold area with the url of your blog's rss feed:

    %%before; httpget; 1 "[rss url]"%% 
  2. Save this content area then look at its properties and write down its ID number.
  3. Create an email with the following code as its contents. Be sure to replace the bold area with your content ID number from the previous step:

    %%[
    VAR @xml, @titles, @title, @dateElements, @descs, @desc, @links, @link, @cnt, @pubdate, @pubdate1, @pubdate2, @pubdates
    Set @xml = TreatAsContent(ContentArea("[Content ID]"))
    /* set content area value to the content area ID that contains the gethttp call to the source xml */
    Set @titles = BuildRowsetFromXML(@xml,"//item/title")
    Set @descs = BuildRowsetFromXML(@xml,"//item/description")
    Set @links = BuildRowsetFromXML(@xml,"//item/link")
    Set @pubdates = BuildRowsetFromXML(@xml,"//item/pubDate")
    set @pubdate1 = field(row(@pubdates,1),"Value")
    set @pubdate2 = v(@pubdate1)
    SET @dateElements = BuildRowsetFromString(@pubdate2, " ")

    SET @rowCount = RowCount(@dateElements)
    SET @theDay = Field(Row(@dateElements,2),1)
    SET @theMonth = Field(Row(@dateElements,3),1)
    SET @theYear = Field(Row(@dateElements,4),1)

    set @monthArray = "Jan Feb Mar Apr Mayt Jun Jul Aug Sep Oct Nov Dec"
    set @monthRows = BuildRowsetFromString(@monthArray, " ")
    var @monthNumeric
    Set @today = Format(Now(),"MM/dd/yyyy")

    for @cntr = 1 to RowCount(@monthRows) do

        if ( field(Row(@monthRows, @cntr),1) == @theMonth ) then
       
        set @monthNumeric = @cntr
        endif
        next @cntr
       
        set @pubDate = Concat(@monthNumeric,"/",@theDay,"/",@theYear)
    /* this for loop converts the pubDate for each item to MM/dd/yyyy format */


    If ( datediff(@pubdate,@today,"D") >= 1 ) Then raiseerror("No New Posts", true)
    Endif
    /* this if statement set the send to fail if there is not new post */

    For @cnt = 1 to 1 do
    /* this for loop can run to the number of items returned (rowcount(@titles)) but must run to at least 1 */
    Set @title = Row(@titles,@cnt)
    Set @desc = Row(@descs,@cnt)
    Set @link = Row(@links,@cnt)
    ]%%

    <div style="border: 0px solid #444; background-color: #FFFFFF; margin: 0.76em 0; padding: 0.76em;">
    <h1 style="font: bold normal 1.0em Arial, Helvetica, sans-serif;">
    <a href='%%= RedirectTo(Field(@link,"Value")) =%%' alias='%%= Field(@title,"Value") =%%'
    title='%%= Field(@title,"Value") =%%' style="color: #000;">%%= Field(@title,"Value") =%%</a></h1>
    <span style="font: normal normal 0.76em Arial, Helvetica, sans-serif; color: #444;">%%= Field(@desc,"Value") =%%</span>
    </div>
    %%[ next @cnt ]%%

  4. Before saving the email, edit the text version of the email so that it is simply a link to your blog. If you do not removeall of the generated content for the text version of the email, the email will not send and the process will fail.
  5. Save the email.
  6. Create a new user initiated send that sends the email you just created to the appropriate list/group.
  7. Create a new program with a send activity that triggers the send you created in the last step and is scheduled to run every day at 11:59pm.
  8. Start the program.

That's all there is to it.