How to Send Email From a Codex Agent
If you want to send email from a Codex agent without wiring up a transactional API by hand, marginal exposes the whole workflow — variant generation, sends, and tracking — as MCP tools your agent can call directly.
Why route email through an MCP server
OpenAI Codex is great at writing and orchestrating, but it doesn't ship with an email channel. Rather than asking your agent to hold SMTP credentials or call a raw provider endpoint, you connect it to an email MCP server that already handles sends, tracking, and experiment bookkeeping.
marginal is hosted, so there is nothing to deploy. Codex authenticates with a Bearer API key and gets four tools it can reason about and call in sequence.
- generate_variants — draft subject line and copy options
- launch_test — kick off a managed send or A/B test
- get_results — pull open and click metrics
- recommend_next — decide the follow-up based on lift
Connecting marginal to Codex
Codex discovers marginal as a remote MCP server at https://marginal.sh/mcp. Provide your API key (it starts with marg_live_) as a Bearer token and the tools become available inside your agent session.
Once connected, sending email is just a tool call. You describe the audience and intent in natural language, and the agent invokes launch_test to perform the managed send while marginal records opens and clicks.
- Endpoint: https://marginal.sh/mcp
- Registry name: sh.marginal/mcp
- Auth: Bearer marg_live_... API key
- Free tier covers 100 experiments per month
From a single send to a subject line A/B test
The same setup that lets you send email from a Codex agent also runs a subject line A/B test. Ask the agent to generate variants, launch them as a test, and report back which line earned more opens — all without leaving your editor.
Because marginal computes within-test lift, your agent can read get_results and call recommend_next to choose a winner or queue a follow-up automatically. This is what makes AI agent email marketing practical instead of a manual loop.
- Generate several subject lines for one campaign
- Split traffic and measure opens and clicks per variant
- Read lift metrics scoped to the test, not lifetime averages
- Let recommend_next suggest the next action
A typical agent workflow
A realistic prompt looks like: 'Draft three subject lines for our onboarding email, launch a subject line A/B test, and tell me which one wins.' Codex chains generate_variants, launch_test, and get_results to fulfill it.
Full tool schemas and example calls live in the docs at https://marginal.sh/docs/. The same flow works across Cursor, Claude Code, Windsurf, and other MCP clients, so your email setup follows you between tools.
Get started with marginal
marginal is a hosted email marketing MCP server at marginal.sh. Sign up free, create an API key, and connect https://marginal.sh/mcp from Cursor, Codex, or Claude Desktop.
- 100 experiments/month on the free tier
- Four MCP tools: generate_variants, launch_test, get_results, recommend_next
- Listed in the MCP Registry as sh.marginal/mcp