email-campaign
Email Campaign Builder
This skill produces channel-ready HTML email campaigns for defined audience segments. It generates strategy briefs, renders live previews in the Treasure Studio artifact panel, supports iterative natural language editing, and pushes finalized emails to Treasure Engage via a TD Workflow.
When to Use This Skill
Use this skill when:
- The user asks to "create an email", "build an email campaign", or "design an email template"
- The user wants to "generate an email for a segment" based on audience data
- The user requests a "preview" of an email in Treasure Studio
- The user says "push to Engage", "ship it", or "send to Engage" to publish a finalized email
- The user needs A/B testing variants for an email campaign
Prerequisites
This skill requires:
- Treasure Studio MCP server (
tdx-studio) — for email preview viapreview_document - tdx CLI — for workflow execution and Engage integration
- (Optional)
engage_email_builderTD Workflow — for automated push to Engage
If Studio preview is unavailable, emails will be saved to disk only. If the Engage workflow is not deployed, the skill falls back to manual HTML export.
Core Principles
1. Strategy Before Design
Always produce a strategy brief before writing any HTML. Analyze the audience segment, determine the right message and offer, then generate the email.
Example brief output:
Segment: Gold Tier — High Intent
Audience: 2,400 active members, 85% email open rate
Message: Urgency — "Your exclusive early access expires Friday"
Offer: No discount (high-intent segment). Use exclusivity + scarcity.
Imagery: Premium lifestyle, curated product selection
2. Offer Logic Is Segment-Driven
Not every segment should receive a discount. Match the offer strategy to the audience profile.
| Segment Profile | Offer Strategy |
|---|---|
| Low/medium-conversion, bronze/silver, inactive >30 days | Discount or incentive |
| Gold/platinum, high intent, active | Urgency, exclusivity, or social proof |
| New members, unknown intent | Welcome series, value education |
3. Email Client Compatibility First
All HTML must render correctly across Outlook, Gmail, Apple Mail, and Yahoo Mail. This means:
- Table-based layout only — no
<div>for structure - All CSS inline — no
<style>blocks (Gmail strips them) role="presentation"on all layout tables- Max width 600px for the content area
cellspacing="0" cellpadding="0"on all tables
See references/email-design-patterns.md for complete HTML patterns.
4. Personalization via Merge Tags
Use Liquid syntax for all dynamic content. Merge tags render as literal text in preview and are replaced at send time by Treasure Engage.
Available merge tags:
{{profile.first_name}}— customer first name{{profile.loyalty_points}}— current points balance{{profile.tier_name}}— loyalty tier (Bronze, Silver, Gold, Platinum){{profile.points_to_next_tier}}— points needed for next tier
Note: These merge tags assume a parent segment with the following output columns:
first_name(STRING)loyalty_points(INTEGER)tier_name(STRING)points_to_next_tier(INTEGER)
Verify your parent segment includes these fields before using merge tags. To list available fields: tdx ps desc <ps_id> -o
Workflow
The skill follows a four-phase loop: Generate → Preview → Edit → Ship.
Phase 1: Generate
When the user requests an email campaign, produce a strategy brief first:
- Segment analysis — identify the audience by loyalty tier, conversion likelihood, and behavioral traits.
- Strategy brief — output a concise brief with: segment name, audience profile, next best channel, message copy, next best offer, and recommended imagery direction.
- HTML email — generate a complete, standalone HTML email following the design patterns in
references/email-design-patterns.md. Use BeeFree-compatible, responsive table-based layout with inline CSS. - Save to disk — write the HTML to
/tmp/email_campaign_preview.html.
Note: /tmp is a temporary location cleared on system restart. Use "push to Engage" or manually export to a permanent location (e.g., ~/email_exports/) before rebooting.
Phase 2: Preview
After generating the HTML, render it in the Treasure Studio artifact panel:
preview_document(path="/tmp/email_campaign_preview.html")
Tell the user: "Here's the email preview. Describe any changes you'd like, or say push to Engage when you're ready."
Phase 3: Edit (iterative)
When the user requests changes:
- Read the current HTML from
/tmp/email_campaign_preview.html. - Apply the requested modifications (copy changes, color updates, image swaps, layout adjustments, CTA rewording, etc.).
- Write the updated HTML back to
/tmp/email_campaign_preview.html. - Re-render the preview with
preview_document. - Repeat until the user approves.
Keep a running list of merge tags used in the email (e.g., {{profile.first_name}}, {{profile.loyalty_points}}). Display these after each preview so the user knows what personalization is active.
Phase 4: Ship to Engage
When the user says "push to Engage", "ship it", "publish", or "send to Engage":
- Read the final HTML from
/tmp/email_campaign_preview.html. - Run the Engage email builder workflow. Refer to
references/engage-integration.mdfor the exact command and parameters. - Report the result and direct the user to check Engage Studio → Email Templates to see the new template.
Common Patterns
Pattern 1: Tier Advancement Campaign
Target gold-tier members close to platinum with urgency and exclusivity.
<h1>{{profile.first_name}}, you're almost there.</h1>
<p>You're just <strong>{{profile.points_to_next_tier}} points</strong> away
from unlocking <strong>Platinum</strong> tier.</p>
When to use: Members within 20% of the next tier threshold who have been active in the last 30 days.
Pattern 2: Win-Back Campaign
Re-engage inactive members with a compelling offer.
<h1>We miss you, {{profile.first_name}}.</h1>
<p>It's been a while — and we've been saving something special for your return.</p>
When to use: Members with no purchase activity in 30+ days, bronze or silver tier.
Pattern 3: A/B Testing Variants
Generate two distinct variants for testing copy or CTA effectiveness.
- Generate Variant A and Variant B with distinct copy or CTA changes.
- Save each to separate files:
/tmp/email_campaign_variant_a.htmland/tmp/email_campaign_variant_b.html. - Preview each in sequence using
preview_document. - When shipping, push each variant as a separate template:
- First push: template named "Campaign Name — Variant A"
- Second push: template named "Campaign Name — Variant B"
- Then configure the A/B test in Engage Studio UI.
When to use: The user explicitly requests A/B testing or you recommend it for campaigns targeting >5,000 recipients.
Best Practices
- Strategy first — Always generate a strategy brief before writing HTML. Never skip audience analysis.
- No discounts for high-intent segments — Use urgency, exclusivity, or social proof for gold/platinum or active users.
- Standalone HTML only — No external stylesheets, no JavaScript, no
<style>blocks. - HTTPS imagery only — Use Unsplash or Pexels. Never use AI-generated images.
- Accessible by default — Include descriptive ALT text on all images.
- Footer in every email — Always include unsubscribe link and preference center link.
- Professional tone — No emojis or conversational phrasing in the email content.
- Track merge tags — Display the list of active merge tags after each preview cycle.
- Test across clients — Design for Outlook, Gmail, Apple Mail, and Yahoo Mail compatibility.
- Save before preview — Always write HTML to disk before calling
preview_document.
Email Size Limits
- Subject line: Keep under 50 characters for mobile display
- Preheader text: 40–90 characters (appears after subject in inbox)
- Total HTML size: Under 100KB for best deliverability
- Image file size: Under 1MB per image
Common Issues and Solutions
Issue: Email renders incorrectly in Outlook
Symptoms:
- Layout breaks, columns misaligned, or background colors missing in Outlook
Solutions:
- Ensure all layout uses
<table>elements, not<div>. - Avoid CSS shorthand (
background→ usebackground-color). - Add
mso-conditional comments for Outlook-specific fixes if needed. - Keep all CSS inline — Outlook strips
<style>blocks.
Issue: Merge tags appear as literal text in sent emails
Symptoms:
- Recipients see
{{profile.first_name}}instead of their actual name
Solutions:
- Verify the Engage template is configured for Liquid rendering.
- Confirm field names match the CDP parent segment output schema (e.g.,
first_name, notfirstName). - Check that the merge tag syntax uses double curly braces:
{{profile.field_name}}.
Issue: engage_email_builder workflow not found
Symptoms:
tdx wf workflows engage_email_builderreturns no results
Solutions:
- The workflow hasn't been deployed to this account yet.
- Offer to export the HTML file so the user can paste it into Engage Studio manually.
- Save the final HTML to
~/email_exports/campaign_name_YYYY-MM-DD.html.
Example:
# Fallback: manual export
cp /tmp/email_campaign_preview.html ~/email_exports/campaign_name_2025-01-15.html
Issue: Images not loading in preview
Symptoms:
- Broken image icons in the Treasure Studio preview panel
Solutions:
- Verify image URLs use HTTPS (not HTTP).
- Confirm the Unsplash/Pexels photo ID is valid.
- Check the
?auto=format&fit=crop&w=1200&q=80query parameters are present.
Issue: Image URLs broken or outdated
Symptoms:
- Images that previously worked now return 404 errors
- Unsplash/Pexels removed the original photo
Solutions:
- Search for a replacement image on Unsplash or Pexels with a similar subject.
- Use the standard photo ID format:
https://images.unsplash.com/photo-{photo_id}?auto=format&fit=crop&w=1200&q=80 - Verify the new image loads in a browser before updating the email.
- For production campaigns, consider uploading images to your own CDN or asset storage for permanence.
Related Skills
- tdx-skills:segment — Create and manage the CDP audience segments that feed into email campaigns.
- tdx-skills:parent-segment — Define master customer tables with the attributes and behaviors used for merge tags.
- tdx-skills:parent-segment-analysis — Query parent segment data to understand audience profiles before generating campaigns.
- tdx-skills:connector-config — Configure Engage activations for segment-triggered email sends.
- workflow-skills:workflow — Manage the
engage_email_builderTD Workflow used to push emails to Engage.
Resources
More from treasure-data/td-skills
pytd
Expert assistance for using pytd (Python SDK) to query and import data with Treasure Data. Use this skill when users need help with Python-based data analysis, querying Presto/Hive, importing pandas DataFrames, bulk data uploads, or integrating TD with Python analytical workflows.
20tdx-basic
Executes tdx CLI commands for Treasure Data. Covers `tdx databases`, `tdx tables`, `tdx describe`, `tdx query`, `tdx auth setup`, context management with profiles/sessions, and output formats (JSON/TSV/table). Use when users need tdx command syntax, authentication setup, database/table exploration, schema inspection, or query execution.
3workflow
Manages TD workflows using `tdx wf` commands. Covers project sync (pull/push/clone), running workflows, monitoring sessions/attempts, task timeline visualization, retry/kill operations, and secrets management. Use when users need to manage, monitor, or debug Treasure Workflow projects via tdx CLI.
3journey
Load when the client wants to create, edit, or manage a CDP customer journey. Use for building journey YAML with segments, activations, and stage steps, modifying journey stages or flow logic (decision points, condition waits, A/B tests), or pushing journey changes to Treasure Data. Also load when the client wants to analyze journey performance, query journey tables, create journey dashboards, or generate journey action reports.
2parent-segment-analysis
Query and analyze CDP parent segment database data. Use `tdx ps desc -o` to get output database schema, then query customers and behavior tables. Use when exploring parent segment data, building reports, or analyzing customer attributes and behaviors.
2connector-config
Writes connector_config for segment/journey activations using `tdx connection schema <type>` to discover available fields. Use when configuring activations - always run schema command first to see connector-specific fields.
2