← Blog

Build a Claude API Sales Email Generator

2026-11-13 · 5 min read · SubToAPI Team

If you're trying to build a Claude API sales email generator, the core task is straightforward: feed Claude structured lead data (name, company, role, pain point, recent trigger event), give it a clear prompt template with tone and length constraints, and parse the output into a format your CRM or outreach tool can send. The hard part isn't the AI call — it's designing prompts that avoid generic-sounding copy and building a pipeline that can run reliably at scale across hundreds or thousands of leads.

This guide walks through the full build: data structure, prompt engineering for sales copy, batching logic, and how to wire it into an HTTPS API so your sales tooling can call it directly.

Why generic prompts produce generic emails

The most common mistake in building a sales email generator is sending Claude too little context and expecting personalization. A prompt like "write a cold email to a SaaS founder about our product" will produce copy that reads like every other AI-generated email — because there's nothing specific for the model to latch onto.

Good sales email generation needs:

Your job when designing the prompt is to force the model to use the data you give it rather than fall back on generic phrasing.

Structuring the input data

Before writing the prompt, decide what fields you'll always have versus what's optional. A reasonable schema:

{
  "first_name": "Priya",
  "company": "Northwind Logistics",
  "role": "VP Operations",
  "trigger": "Posted about warehouse automation delays last week",
  "pain_point": "Manual inventory reconciliation taking 20+ hours/week",
  "product_value": "Automated reconciliation in under 2 minutes",
  "proof_point": "Cut reconciliation time 90% for a similar 200-person logistics firm",
  "sender_name": "Alex",
  "sender_company": "FlowStock",
  "cta": "15-minute call this week"
}

Missing fields should degrade gracefully — if you don't have a trigger event, the prompt should instruct Claude to lean harder on the pain point instead of inventing a fake trigger.

Writing the prompt

A system prompt that constrains tone, length, and structure works better than a one-off instruction per email. Example:

You are a sales copywriter. Write a cold outreach email using ONLY the facts provided below.
Do not invent statistics, customer names, or trigger events not given to you.

Rules:
- Subject line: under 50 characters, no clickbait
- Body: 80-120 words, plain text, no bullet points
- Open with the trigger or pain point, not an introduction
- Include exactly one proof point if provided
- End with one specific, low-friction CTA
- Sign off with sender name only, no title

If a field is missing, skip referencing it rather than guessing.

Pass the lead JSON as the user message. This separation — fixed rules in the system prompt, variable data in the user message — makes the pipeline easy to maintain and test.

Calling the API

Here's a minimal implementation using SubToAPI's HTTPS endpoint, which works like Claude's native Messages API but adds application-level keys, usage metadata, and team billing:

async function generateSalesEmail(lead) {
  const response = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "claude-sonnet-4",
      max_tokens: 300,
      system: SALES_EMAIL_SYSTEM_PROMPT,
      messages: [
        { role: "user", content: JSON.stringify(lead) }
      ]
    })
  });

  const data = await response.json();
  return data.content[0].text;
}

If you're integrating Claude into an internal sales tool or a script that your team will run repeatedly, using an application API key instead of a shared personal key matters — it lets you track usage per generator, rotate keys without touching every script, and keep this separate from other Claude usage in your org. See /docs/quickstart for setup and /docs/messages for the full request format.

Batching without rate-limit pain

Sales teams usually need to generate emails for a list, not one lead at a time. Running requests sequentially is slow; firing them all at once risks hitting rate limits. A simple concurrency-limited batch runner handles this well:

async function generateBatch(leads, concurrency = 5) {
  const results = [];
  let index = 0;

  async function worker() {
    while (index < leads.length) {
      const lead = leads[index++];
      try {
        results.push({ lead, email: await generateSalesEmail(lead) });
      } catch (err) {
        results.push({ lead, error: err.message });
      }
    }
  }

  await Promise.all(Array.from({ length: concurrency }, worker));
  return results;
}

Log failures separately and retry them in a second pass rather than failing the whole batch. For large lists (500+), write results to a queue or database table incrementally instead of holding everything in memory.

Parsing output for your CRM

Instead of returning free text, have Claude return structured JSON so you can drop the subject line and body directly into your CRM fields:

Return your output as JSON with keys "subject" and "body". No other text.

Validate the JSON before writing it — wrap the parse in a try/catch and flag malformed responses for manual review rather than silently sending broken emails.

Quality control before anything goes out

Automated generation should never skip human review for cold outreach at scale. A practical workflow:

  1. Generate emails in batch
  2. Run a second Claude pass that scores each email 1-5 on specificity and flags generic-sounding ones
  3. Route anything scoring below 4 to a human editor
  4. A/B test subject lines across a small segment before full send

This two-pass approach — generate, then critique — consistently catches emails that are technically correct but sound robotic.

Getting this running quickly

If you want to prototype this without managing your own Claude account infrastructure, SubToAPI gives you a working endpoint in minutes: sign up, generate a sub_live_... key, and start sending requests. Streaming is supported if you want to show generation progress in a UI (/docs/streaming), and tool use is available if you want Claude to pull lead data from a CRM API mid-generation (/docs/tools). Plans start at €9/month for solo use, with team seats at €19 and €49 for larger usage — see /pricing. There's a free trial at /signup if you want to test the generator before committing.

questions

Does Claude write better sales emails than templates alone? Only when given specific, real data per lead. Without a genuine trigger event or pain point, output defaults to generic phrasing that performs no better than a static template.

How many leads can I process in one batch? There's no hard limit from the model side, but use bounded concurrency (5-10 parallel requests) and write results incrementally so a crash doesn't lose your whole batch.

Should I let the generator send emails automatically? For cold outreach, route low-scoring or unusual leads to human review first. Fully automated sends work better for warm, templated follow-ups where the data quality is already high.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →