← All guides marginal.sh

How to Send Email From a Codex Agent

Updated June 2026 · Hosted email MCP server

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.

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.

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.

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.

Documentation · Sign up · FAQ