How I Built an AI Cold Email Generator with Next.js and OpenAI
Last weekend, I sat down with a simple idea: build an AI tool that writes personalized cold emails. By Sunday night, I had a working SaaS product deployed on Vercel. Here's the entire technical journey, what worked, what
Last weekend, I sat down with a simple idea: build an AI tool that writes personalized cold emails. By Sunday night, I had a working SaaS product deployed on Vercel. Here's the entire technical journey, what worked, what didn't, and what I'd do differently.
The Problem
I've been doing B2B outreach for a while now. The biggest pain point? Writing cold emails that don't sound like templates. You know the ones:
"Hi {firstName}, I noticed your company {companyName} is doing great things in {industry}..."
These emails get ignored. Everyone knows they're automated. But writing truly personalized emails takes forever. I was spending 3-4 hours a day just crafting outreach messages.
The Tech Stack
Here's what I chose and why:
- Next.js 14 (App Router) - Server components for the AI processing, client components for the form UI
- OpenAI API (GPT-4o-mini) - Good enough quality at a fraction of GPT-4 cost
- Tailwind CSS - Fast styling without leaving the editor
- Vercel - Deploy in seconds, zero DevOps
- Stripe - Payment processing with webhook handling
Total monthly infrastructure cost: under $5 (OpenAI usage is the main variable).
The Architecture
The app is surprisingly simple. Here's the core flow:
User Input -> API Route -> OpenAI Completion -> Formatted Email -> Display
The API route handles the heavy lifting:
// app/api/generate/route.ts
export async function POST(req) {
const { prospect, context, tone } = await req.json();
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{
role: "system",
content: "You are a cold email expert. Write a personalized cold email that is concise, relevant to the prospect, and has a clear CTA."
},
{
role: "user",
content: "Write a cold email for: " + prospect + " Context: " + context + " Tone: " + tone
}
],
temperature: 0.7,
max_tokens: 300
});
return Response.json({
email: completion.choices[0].message.content
});
}
Key Technical Decisions
Why GPT-4o-mini over GPT-4?
Cost. GPT-4o-mini is roughly 15x cheaper than GPT-4 for input tokens. For cold emails (short input, short output), the quality difference is negligible. My users are generating hundreds of emails. At GPT-4 prices, the margins would be razor thin.
Why Server Components?
The generation form is a client component (needs interactivity), but everything else is server-rendered. This means:
- Fast initial page load
- SEO-friendly landing page
- Less JavaScript shipped to the browser
Prompt Engineering Was 80% of the Work
This surprised me. The actual Next.js code took maybe 4 hours. Getting the prompts right took the entire rest of the weekend.
The key insight: constraints produce better emails. When I told the AI "write a cold email," I got generic garbage. When I said "write a 3-sentence email that references their latest blog post and asks one specific question," the output was dramatically better.
I ended up with a prompt template that includes:
- Word count limits (under 75 words)
- Structure requirements (hook, value prop, CTA)
- Anti-patterns to avoid ("I hope this finds you well")
- Tone matching based on industry
Stripe Integration in 30 Minutes
Stripe's Next.js integration is ridiculously smooth now. The checkout flow:
- User clicks "Subscribe"
- Redirect to Stripe Checkout
- Webhook fires on successful payment
- Update user status in the database
What I Shipped
The MVP has three features:
- Single email generation - Paste prospect info, get an email
- Batch generation - Upload a CSV, get emails for all prospects
- Tone control - Professional, casual, or direct
That's it. No email sending. No CRM integration. No analytics dashboard. Just the core value: generate good cold emails fast.
I priced it at $9/month with unlimited generations. Low enough that any SDR or founder would try it without needing approval from their boss.
Lessons Learned
1. Deploy on day one. I pushed to Vercel after the first 2 hours, before the AI even worked. Having a live URL kept me motivated and let me test on mobile early.
2. Don't build auth from scratch. I initially tried rolling my own auth. Wasted 3 hours. Switched to a simple email magic link flow and saved my sanity.
3. Rate limiting is essential. Without it, one user could burn through your entire OpenAI budget in minutes. I added a simple token-bucket rate limiter in the API route.
4. Error handling for AI is different. Sometimes the AI returns garbage. Sometimes it times out. Sometimes it ignores your constraints. You need graceful fallbacks and retry logic.
Current Numbers
It's been a few weeks since launch:
- Around 50 signups on the free tier
- A handful of paid subscribers
- Average generation time: 2-3 seconds
Not viral numbers, but the product works and people are using it. The focus now is distribution, not features.
What's Next
I'm working on:
- Email sequence generation (not just single emails)
- Better prospect research integration
- A Chrome extension for LinkedIn prospecting
Try It
If you're doing any kind of cold outreach, give it a shot: ColdMailAI. The free tier lets you generate emails without signing up.
I'm building this in public, so I'll be sharing more updates here. Happy to answer any technical questions in the comments.
What's your experience with AI-generated emails? Have you found a sweet spot between automation and personalization? Let me know below.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.