DEV Community

S Gr
S Gr

Posted on

How to Build an AI-Powered Email Sequence Generator Using Claude API and n8n

How to Build an AI-Powered Email Sequence Generator Using Claude API and n8n

This article mentions a tool I use; the link at the end is an affiliate link.

Email sequences remain one of the most profitable digital products to sell in 2026. But creating personalized, high-converting sequences manually takes hours. In this tutorial, I'll show you how to build an automated email sequence generator that uses Claude AI to create customized sequences based on user input—no coding required beyond basic JSON.

What You'll Build

A workflow that:

  1. Accepts user input (niche, product type, audience)
  2. Generates a 5-email welcome sequence using Claude API
  3. Formats the output as a downloadable document
  4. Can be packaged as a paid tool or lead magnet

Prerequisites

  • n8n account (self-hosted or cloud, free tier works)
  • Anthropic API key (Claude)
  • Basic understanding of workflow automation
  • 2-3 hours to set up and test

Step 1: Set Up Your n8n Workflow

n8n is an open-source automation platform that connects APIs without writing full applications.

  1. Create a new workflow in n8n
  2. Add a Webhook node as your trigger
  3. Set it to POST method
  4. Copy the webhook URL—this becomes your tool's endpoint

Your webhook should accept JSON with these fields:

{
  "niche": "fitness coaching",
  "product": "online course",
  "audience": "busy professionals",
  "tone": "friendly and motivating"
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure Claude API Integration

Add an HTTP Request node after your webhook:

  1. Method: POST
  2. URL: https://api.anthropic.com/v1/messages
  3. Authentication: Add header x-api-key with your Anthropic API key
  4. Add header anthropic-version: 2023-06-01
  5. Add header content-type: application/json

In the body, use this structure:

{
  "model": "claude-3-5-sonnet-20241022",
  "max_tokens": 2500,
  "messages": [{
    "role": "user",
    "content": "Create a 5-email welcome sequence for {{$json.niche}} selling {{$json.product}} to {{$json.audience}}. Use a {{$json.tone}} tone. Format each email with Subject:, Body:, and Purpose: labels. Make emails 150-200 words each."
  }]
}
Enter fullscreen mode Exit fullscreen mode

The double curly braces pull data from your webhook input.

Step 3: Parse and Format the Output

Claude returns text in a specific JSON structure. Add a Code node with this JavaScript:

const response = $input.first().json;
const emailContent = response.content[0].text;

// Split into individual emails
const emails = emailContent.split(/Email \d:/).filter(e => e.trim());

const formatted = emails.map((email, index) => {
  const subjectMatch = email.match(/Subject:(.*?)(?=Body:|$)/s);
  const bodyMatch = email.match(/Body:(.*?)(?=Purpose:|$)/s);

  return {
    number: index + 1,
    subject: subjectMatch ? subjectMatch[1].trim() : '',
    body: bodyMatch ? bodyMatch[1].trim() : '',
    raw: email.trim()
  };
});

return [{ json: { emails: formatted, fullText: emailContent } }];
Enter fullscreen mode Exit fullscreen mode

This extracts each email into a structured format you can work with.

Step 4: Create a Downloadable Output

Add a Code node to format as markdown:

const data = $input.first().json;
let markdown = '# Your Custom Email Sequence\n\n';

data.emails.forEach(email => {
  markdown += `## Email ${email.number}\n\n`;
  markdown += `**Subject:** ${email.subject}\n\n`;
  markdown += `${email.body}\n\n`;
  markdown += '---\n\n';
});

return [{ json: { markdown }, binary: { data: Buffer.from(markdown) } }];
Enter fullscreen mode Exit fullscreen mode

Add a final Respond to Webhook node that returns the markdown or saves it to Google Docs/Notion.

Step 5: Test Your Generator

Use a tool like Postman or curl to test:

curl -X POST your-webhook-url \
  -H "Content-Type: application/json" \
  -d '{
    "niche": "productivity coaching",
    "product": "membership site",
    "audience": "entrepreneurs",
    "tone": "authoritative but warm"
  }'
Enter fullscreen mode Exit fullscreen mode

You should receive a formatted email sequence in seconds.

Monetization Options

  1. Sell API access: Charge $9-29/month for unlimited generations
  2. One-time purchases: $47-97 for a Notion template + 50 generations
  3. White-label: Package for agencies at $297-497
  4. Lead magnet: Offer 1 free sequence, upsell to templates

Improving Your Tool

When I was building out the marketing funnel for a similar tool, I used Perpetual Income 365 to handle the email automation and upsell sequences, which saved me from building that entire system from scratch. It's particularly useful if you're not familiar with setting up complex email funnels.

Beyond that, consider:

  • Adding industry-specific templates to your prompts
  • Integrating with Stripe for payments
  • Creating a simple frontend with Typeform or Fillout
  • Offering A/B tested subject line variations

Cost Breakdown

  • n8n: Free (self-hosted) or $20/month (cloud)
  • Claude API: ~$0.50 per sequence generation (2500 tokens)
  • Hosting (if needed): $5-10/month

At $19/month subscription with 20 customers, you're profitable after month one.

Next Steps

  1. Build the basic workflow this week
  2. Generate 10 test sequences in different niches
  3. Create a simple landing page
  4. Share in communities like Indie Hackers for feedback
  5. Iterate based on user requests

The key is starting with a working tool that solves a real problem. You can always add features later based on what users actually need, not what you think they want.

This approach works because it combines genuine AI capabilities with a proven need (email marketing) and packages it in a way that saves people time. No hype needed—just a tool that works.


The tool mentioned above is an affiliate link (disclosed at top): Perpetual Income 365

Top comments (0)