求助Marketo邮件开发者:如何在Marketo邮件模板中添加XML Feed
Hey Felix, I get where you're stuck—web hooks in Marketo run server-side as part of campaigns, so their data isn't directly accessible in email templates out of the box. Let's walk through two practical solutions to get your XML feed content into your emails:
Option 1: Use Velocity Email Scripting (Direct Template Integration)
This is the most straightforward approach if you want to pull the XML content directly when the email is sent.
Step 1: Enable Email Scripting
First, make sure your Marketo instance has Email Scripting enabled. If you don't see the "Email Script" token option, reach out to your Marketo admin or support team to turn it on—this feature isn't enabled by default.
Step 2: Create an Email Script Token
- Go to Design Studio > My Tokens (or the folder where your email template lives).
- Click New > Email Script.
- Paste the following Velocity code, adjusting it to match your XML feed's structure:
#set($xmlFeedUrl = "http://depts.washington.edu/uweb/s-n/w.xml") #set($xmlResponse = $http.get($xmlFeedUrl)) #if($xmlResponse.status == 200) #set($xmlDocument = $xml.parse($xmlResponse.body)) <!-- Customize this section based on your XML's actual structure --> <div class="xml-feed-content"> <h3>Latest Updates</h3> <ul> #foreach($item in $xmlDocument.rss.channel.item) <li> <strong>$item.title</strong> <p>$item.description</p> </li> #end </ul> </div> #else <p>We're unable to load the latest content right now. Please check back later.</p> #end
- Save the token (e.g., name it
XML Feed Content).
Step 3: Add the Token to Your Email Template
In your email template, insert the token using the syntax: {{my.XML Feed Content}}
Pro Tips:
- Use Marketo's XML selector syntax to target the right nodes (e.g.,
$xmlDocument.rootNode.childNode). You can test your XML structure using tools like XMLTreeViewer to map out the paths. - Be aware of Marketo's
$http.gettimeout limit (~10 seconds)—ensure your XML feed loads quickly to avoid email delivery delays.
Option 2: Web Hook + Custom Object + Smart Campaign (Cached Data)
Use this method if you need to cache the XML data (e.g., for slower feeds or to avoid repeated HTTP calls) or if you want to manipulate the data before it's used in emails.
Step 1: Create a Custom Object
- Go to Admin > Custom Objects > New Custom Object.
- Name it something like
XML Feed Itemand add fields that match your XML content (e.g.,Title,Description,Publish Date).
Step 2: Configure a Web Hook
- Go to Admin > Web Hooks > New Web Hook.
- Set the URL to your XML feed address, Request Type to
GET, and Response Type toXML. - Under Response Mappings, map XML elements to your Custom Object fields (e.g., map
/rss/channel/item/titleto theTitlefield).
Step 3: Build a Smart Campaign to Update Data
- Create a new Smart Campaign in Marketing Activities.
- Set a trigger (e.g., Schedule to run daily) or a batch campaign to refresh the data.
- Add the Call Web Hook flow action, select your web hook, and configure it to create/update records in your Custom Object.
Step 4: Reference Custom Object Data in the Template
In your email template, use the Custom Object field syntax to insert content:
{{my.XML Feed Item - Title}} {{my.XML Feed Item - Description}}
Key Considerations
- Firewall Access: Ensure Marketo's IP addresses are allowed to access your XML feed domain—check Marketo's documentation for their current IP ranges.
- Testing: Always send test emails to verify the content loads correctly, and use Marketo's preview feature to debug Velocity scripts.
- Rate Limits: If using Velocity, avoid hitting the XML feed too frequently (Marketo doesn't enforce strict limits, but respect the feed's rate policies).
内容的提问来源于stack exchange,提问作者Felix B

