Building Powerful AI Email Workflows with the Afterdraft API
API Overview and Authentication
The Afterdraft API is designed for developers who want to give their AI agents full email capabilities without managing mail servers, DNS records, or deliverability infrastructure. Every operation your agent needs, from provisioning an address to sending a message to processing an inbound reply, is available through a clean REST interface with predictable JSON payloads and standard HTTP status codes.
Sending Email Programmatically
The core workflow starts with the Send endpoint. Your agent constructs a message with a recipient, subject, body in HTML or plain text, optional attachments, and threading headers. Afterdraft handles MIME encoding, DKIM signing, and delivery. The API returns a message ID you can use to track delivery status, opens, clicks, and replies. For agents that send at volume, the Batch Send endpoint accepts up to 1,000 messages per call with individual personalization.
Processing Inbound Email with Webhooks
Inbound email processing is event-driven. You register a webhook URL for each agent address, and Afterdraft posts a structured payload every time a message arrives. The payload includes the full parsed email: sender, recipients, subject, plain-text body, HTML body, attachment download URLs, and In-Reply-To and References headers for threading. Your agent can process this payload, generate a response, and call the Send endpoint to reply, all within a single request cycle.
Routing, Scheduling, and Conditional Logic
For more complex workflows, the API offers routing rules, conditional logic, and scheduled sending. You can define rules that forward certain inbound messages to different agents based on subject-line keywords, sender domain, or custom headers. Scheduled sends let your agent compose a message now but deliver it at a specific future time, useful for follow-up sequences and time-zone-aware outreach. Conditional branches can pause a sequence until a reply is received or a link is clicked.
Error Handling and Observability
Error handling and observability are first-class concerns. Every API response includes a request ID for tracing. The Events endpoint streams a real-time log of sends, deliveries, bounces, opens, clicks, and replies for each agent address. Webhooks support automatic retries with exponential backoff, and a dead-letter queue captures any payloads your endpoint fails to acknowledge. This makes it straightforward to build reliable, production-grade email workflows.
The best way to get started is to clone the Afterdraft quickstart repository, which includes working examples in Python and Node.js for the most common workflows: sending a single email, processing an inbound message, and running a multi-step follow-up sequence. Each example is under 50 lines of code and includes inline comments explaining every API call.