Autonomous Sales: Building an AI Outreach Agent with Apollo + AgentMail
Build a sales agent that prospects with Apollo, writes personalized emails, and sends via AgentMail — fully autonomous, pay-per-action.
Sales outreach is a natural fit for AI agents: it's repetitive, requires personalization, and has clear metrics. This tutorial builds a fully autonomous sales agent that prospects, writes, and sends — paying per-action via x402.
The Agent Pipeline
Apollo (prospecting) → LLM (personalization) → AgentMail (sending)
$0.02/lead $0.01/email $0.005/sendTotal cost per personalized outreach: ~$0.035
Step 1: Find Leads with Apollo
async function findLeads(criteria: object) {
const result = await m.pay({
url: "https://api.apollo.io/v1/people/search",
method: "POST",
body: JSON.stringify({
...criteria,
per_page: 25,
}),
})
return result.data.people
}Apollo provides rich prospect data: name, title, company, email, LinkedIn, and more. Cost: ~$0.02 per lead.
Step 2: Generate Personalized Emails
async function writeEmail(lead: any, context: string) {
const result = await m.pay({
url: "https://openrouter.ai/api/v1/chat/completions",
method: "POST",
body: JSON.stringify({
model: "anthropic/claude-sonnet-4-6",
messages: [{
role: "user",
content: `Write a personalized cold email to ${lead.name}, ${lead.title} at ${lead.company}.
Context: ${context}
Keep it under 150 words. Be specific about their company.`,
}],
}),
})
return result.data.choices[0].message.content
}Step 3: Send via AgentMail
async function sendEmail(to: string, subject: string, body: string) {
const result = await m.pay({
url: "https://api.agentmail.dev/v1/send",
method: "POST",
body: JSON.stringify({
to,
subject,
body,
from: "agent@yourcompany.com",
}),
})
return result.data
}Full Pipeline
async function runOutreach(criteria: object, context: string) {
const leads = await findLeads(criteria)
for (const lead of leads) {
const email = await writeEmail(lead, context)
await sendEmail(
lead.email,
`Quick question about ${lead.company}`,
email
)
// Respect rate limits
await new Promise(r => setTimeout(r, 2000))
}
return { sent: leads.length }
}Cost Analysis
| Volume | Daily Cost | Cost per Lead |
|---|
|--------|-----------|--------------|
| 25 leads/day | $0.88 | $0.035 |
|---|---|---|
| 500 leads/day | $17.50 | $0.035 |
Compare this to a human SDR's cost: $200-400/day for similar output volume. The agent costs 98% less.
Safety Controls
Results Tracking
Monitor via Mithril dashboard: