How to send email from Claude Code: worked tool-call examples
Send email from Claude Code using the send.io MCP server with worked examples, exact payloads, and failure modes for production agents. This guide walks through three real tool calls with request/response traces so you can deploy email functionality that fails loudly instead of silently.
On this page
TL;DR: Claude Code has no native email capability. Connect it to the send.io MCP server to give your agent a scoped, observable email tool that fails loudly. The server exposes 160 tools over JSON-RPC 2.0, covering email sending and listing, domains, webhooks, templates, and agent inboxes through one connection. This article shows the exact tool calls, request payloads, and failure modes so you can deploy email functionality without silent failures.
Claude Code can generate a send_email function in seconds, but it cannot send the email without an external tool. That tool requires credentials, a schema, and a failure contract. This article walks through three worked examples using the send.io MCP server: a plain-text send, an HTML send with a React Email template, and a draft-then-send flow, then documents exactly what happens when things break.
Prerequisites for Claude Code email integration
You need three things before connecting Claude Code to email: Claude Code itself, a send.io account with a verified domain, and a way to authenticate, either a send.io API key or OAuth sign-in. For bearer-token authentication, the hosted MCP server uses the same API key as the REST API; it also supports OAuth sign-in, which needs no key. To use the key, register the server with claude mcp add --transport http sendio followed by the send.io MCP endpoint URL, and pass the key in an Authorization: Bearer header with the --header flag. All sends still require a verified sender domain to pass DMARC alignment, and if your domain is not verified, expect the API to reject the request with an authorization-class error (this article uses 403 as an illustrative status, so confirm the exact code in the API reference), which is the behavior you want: loud failures over silent drops.
Configuring Claude Code
Add the MCP server configuration to the scope that fits how your team works. Claude Code resolves three MCP server scopes: local (the default, private to you, and stored per project), project (shared with your team through a .mcp.json file in your repository root), and user (available across all your projects). Local-scope and user-scope definitions live in your user-level Claude Code config file, while project-scope definitions live in .mcp.json, which travels with the repo.
When the same server name is defined in more than one scope, local overrides project, and project overrides user. You can choose a scope when you register a server by passing a scope option to claude mcp add (the flag is typically --scope, but run claude mcp add --help to confirm the exact name in your version). For the send.io MCP server, the example below uses the documented local stdio mode, which runs the CLI with the free-inbox tools and needs no API key, in the mcpServers format that .mcp.json uses. For the hosted server, register an HTTP connection and pass your API key as a bearer token in the Authorization header, as described in the prerequisites.
{
"mcpServers": {
"sendio": {
"command": "sendio",
"args": ["mcp", "serve", "--tools", "free-inbox"]
}
}
}
Configuring the send.io MCP server
The hosted MCP server operates at POST /mcp using JSON-RPC 2.0 over Streamable HTTP. For bearer-token authentication, the server uses the same API key as the REST API, so you do not manage separate credentials; it also supports OAuth sign-in, which needs no key. For local testing without an account, use the CLI to run sendio mcp serve --tools free-inbox, which exposes five free-inbox tools: free_inbox_create, free_inbox_list, free_inbox_wait_for_email, free_inbox_read, and free_inbox_connect. When you are signed out, these are the only tools available. This local stdio mode lets you test Claude Code email sending against disposable inboxes before provisioning production credentials.
Setting up your verified email domain
Add your sending domain in the send.io dashboard, then add the DKIM, SPF, and return path DNS records to your DNS provider. Verification completes when DNS propagates. Until verification completes, expect the API to reject send attempts with a domain verification error, which this article calls unverified_domain for illustration (confirm the exact error code in the API reference). This prevents your agent from attempting sends that would fail DMARC alignment at the recipient's server. If you are testing without a domain, use the instant agent mailbox feature, which provides a receive-only address at name@org.sendioinbox.com without DNS configuration.
Configuring the send.io MCP for Claude Code
The send.io MCP integration exposes two surfaces: the hosted server with 160 tools for production use, and the local stdio mode with five tools for testing. According to send.io, the hosted server exposes a broad tool set spanning email sending and listing, domains, webhooks, templates, and agent inboxes. The local mode exists for evaluating the integration against disposable inboxes, so you can test connectivity before configuring DNS or provisioning production credentials. Choose the hosted server for production Claude Code email sending, and use local mode only for initial connectivity tests.
Surface | Tools | Auth | Use Case |
|---|---|---|---|
Hosted MCP | 160 | API key as bearer token (same as REST API) | Sending and listing, domains, webhooks, templates, and agent inboxes |
Local stdio | 5 | None (no account or API key required) | Testing against disposable free inboxes |
Registering MCP tools for email
Claude Code discovers available tools by sending a tools/list JSON-RPC request to the MCP server. The server responds with a schema defining each tool's parameters. For email, the schema covers tools for sending and listing messages, alongside categories like domains, webhooks, templates, and agent inboxes. Treat that schema as the source of truth for both tool names and required fields like to and subject, and expect incomplete calls to fail validation before any network request occurs. The send tool in this article's examples, send-email, and the draft tools in Example 3 (create-draft, get-draft,draft, and send-draft)draft) are the names listed in the send.io MCP reference, though the draft argument shapes here are still illustrative. Scheduling uses the documented scheduled_at field on send-email, and the update-email and cancel-email tools reschedule or cancel a scheduled email. The send.io MCP page and the tools/list response define the actual tool names, so read the exact names before copying any example. That fail-fast behavior keeps malformed requests from reaching the email infrastructure.
Standardizing MCP email request payloads
Every email tool call uses a consistent JSON structure. The send examples in this article follow the documented send-email APIs: schema, which mirrors the POST /emails body: from, to, subject, and top-level bodyhtmlhtml or text htmlfields. There is no nested body object. The response and draft shapes are illustrative, modeled on common conventions, so confirm the exact field names against the schema from tools/list and the API reference. Standardizing on one contract means your agent does not need to construct raw MIME messages or handle SMTP envelope formatting. The MCP server translates the tool call into the appropriate API request, so you work at the semantic level of "send this message" rather than "open a socket and issue RCPT TO commands."
Required fields for email delivery
Plan for three fields on every send, because required fields vary across MCP server implementations: to (string or array of strings), subject, and bodymessage content in either text or html as a top-level field. A from address (a verified sender) may also be required depending on server configuration, since some configurations fall back to a default sender when it is omitted. Optional fields typically include cc, bcc, and attachments, and an Idempotency-Key header is the standard mechanism for safe retries, matching common email API conventions. Scheduling is a field on the send itself: send-email mirrors the API's snake_case fields, including scheduled_at, which takes a full ISO 8601 timestamp with a time zone or a relative value like "in 30 minutes", at most 30 days ahead. Changes after the send go through dedicated tools: update-email reschedules a scheduled email, and cancel-email cancels it before it is sent. If you omit a required field, expect a validation error (illustratively a 400) that lists the missing fields before the request reaches the email infrastructure, so you get immediate feedback in the terminal. Confirm the exact status code and error body in the API reference.
Example 1: send a plain-text email from the terminal
Prompt Claude Code: "Send an email to user@example.com with subject 'Test' and body 'Hello from Claude Code.'" Claude Code formats this as a call to the send_emailsend-send-email tool it discovered through tools/list. Unlike generating a script you must run, this is a direct tool invocation: Claude Code acts as the MCP client, constructs the JSON-RPC request, and executes it immediately. You see the result in the terminal without switching contexts.
Implementation: plain-text email payload
The tool call generates a JSON-RPC 2.0 request like this one. The send-emailtool takes from, to, subject, and top-level text or html fields. Confirm the bodyexact schema in your server's tools/list:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "send-email",
"arguments": {
"from": "agent@yourdomain.com",
"to": "user@example.com",
"subject": "Test",
"text": "Hello from Claude Code"
}
}
}
Claude Code tool invocation patterns
Claude Code distinguishes between generating code and invoking tools. When you ask it to send email, it recognizes the send-email toolsend_email from the MCP handshake and constructs the tool call directly. This differs from asking Claude to "write a script that sends email," which would produce Python or Node.js code you then execute. The tool invocation happens synchronously: Claude Code waits for the MCP server response and reports the result. This is the difference between terminal email with Claude as an active agent versus Claude as a code generator.
Request and example response payload
The MCP server translates the tool call into a REST API request to the send.io send endpoint with your bearer token. A successful response returns a result payload. The shape below is illustrative, so confirm the actual response fields in the API reference:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"id": "msg_01234567890abcdef",
"status": "queued",
"timestamp": "2026-11-23T14:32:00Z"
}
}
In this illustrative shape, the id field is your message identifier for tracking, and a queued status means the API request succeeded and the message is waiting in the queue to be sent out, so it has not reached the receiving server yet. The msg_... ID format, the status values, and the timestamp field are not documented by send.io, so confirm them before you parse the response.
Validating successful email delivery
Check the send.io dashboard event log for the message ID. A delivered event typically shows a delivered status, a timestamp, and the recipient address. If you have configured event webhooks, your endpoint receives a POST with the delivery confirmation. The webhook payload includes the message ID, the event type, the timestamp, the recipient, and failure diagnostics where relevant. Confirm the exact event type names in the webhook documentation. send.io delivery webhooks never carry message content: the payload holds metadata and failure diagnostics only, so fetch the message by ID if your agent needs the body. Confirm the exact payload shape in the API reference before building parsing logic around it.
Example 2: send HTML email with a React Email template
Transactional email often requires HTML formatting: password resets, receipts, and notifications need structure that plain text cannot provide. React Email lets you write components that render to static HTML. The render function converts your JSX to an HTML string before the tool call, ensuring the email contains no React runtime dependencies.
Structuring React Email payloads
The documented send-email tool send_emailaccepts a top-level html field alongside from, to, and subject, so there is no nested body object. Confirm the exact field names in your server's tools/list schema. You pass the rendered HTML string directly:
{
"html": "<html><body><h1>Welcome</h1><p>Your account is ready.</p></body></html>"
}
Tool call structure for HTML emails
Claude Code constructs the tool call with the html field populated instead of text. If you ask Claude to "send the welcome email to user@example.com using the WelcomeTemplate," it first executes the render step locally (if you have a build step that compiles React Email components), then passes the resulting HTML string to the send_emailsend-send-email tool. The tool call structure remains identical, and only the content field changes from bodytexttext to html.
Raw payload and execution trace
The execution trace shows two distinct steps. First, the local render:
import { render } from '@react-email/render';
import WelcomeEmail from './emails/welcome';
const html = render(WelcomeEmail({ username: 'Alice' }));
Then thesend-email tool call with the rendered output:
{
"method": "tools/call",
"params": {
"name": "send-email",
"arguments": {
"from": "agent@yourdomain.com",
"to": "alice@example.com",
"subject": "Welcome to the platform",
"html": "<html><body>...</body></html>"
}
}
}
Rendering React components for email
Use the render function from @react-email/render to convert components to static HTML. Note that React hooks like useState or useEffect do not work in this context because the output is static markup. The render happens in your local environment or CI pipeline, not in the MCP server. This separation ensures the email HTML is fully formed before the tool call, so the MCP server handles delivery only, not template compilation.
Example 3: draft-then-send flow with a manual approval checkpoint
Production agents benefit from a draft-then-send flow that creates a review checkpoint before delivery. The send.io MCP reference documents this flow for agent inboxes: create-draft stages a message in an inbox, get-draft returns the draft with its recipients, content, and state, and send-draft sends it as it is. update-draft changes a pending or failed draft, and delete-draft discards one so it is never sent.
Confirm the exact tool names and argument schemas in your server's tools/list response before copying the examples below, because the tools your client exposes can be filtered. Where your MCP client supports per-tool approval rules, you can require manual approval on send-draft, which prevents autonomous sends from reaching recipients without human verification.
Securing email sends with manual approval
Configure your MCP client settings to require approval for the send-draft tool. When Claude Code attempts the send, it pauses for your approval, so you can review the request and abort it if anything looks wrong. This checkpoint catches prompt injection attacks or logic errors where the agent constructs an inappropriate message. Because the draft exists in the send.io system with a draft_id before it is sent, you can call get-draft to inspect its full content, recipients, and state before approving, and call delete-draft to discard it if it looks wrong.
Required parameters for email delivery
The draft flow uses three documented tools in sequence: create-draft stages the message, get-draft returns it for inspection, and send-draft sends it. The create-draft call takes the target inbox plus the message content (recipients, subject, and top-level text or html) and returns a draft identifier that the next two calls reference. The request and response shapes below are illustrative, so take the exact parameter names from tools/list. Note that send-email itself does not take a draft_id parameter. It accepts inline html or text, a published template, or a transactional email by ID, so use send-draft rather than send-email to send a staged draft. send-draft sends the draft as it is, so make any edits with update-draft before approval. The draft-then-send flow creates an audit trail: the draft represents intent, and the send represents execution.
JSON structure for email drafting
First, the create-draft request (an illustrative shape):
{
"method": "tools/call",
"params": {
"name": "create-draft",
"arguments": {
"inbox_id": "inbox_123",
"to": "user@example.com",
"subject": "Your invoice",
"text": "Invoice attached."
}
}
}
Illustrative response (the draft ID field and its ID format are not documented, so confirm them against the tool's response schema):
{
"result": {
"id": "draft_987654321"
}
}
Inspect the draft with get-draft, then send it with send-draft
Before approval, get-draft returns the draft with its recipients, content, and state (an illustrative shape, so check the argument names against your server's schema):
{
"method": "tools/call",
"params": {
"name": "get-draft",
"arguments": {
"inbox_id": "inbox_123",
"draft_id": "draft_987654321"
}
}
}
After you approve, send-draft sends the draft now, as it is (an illustrative shape):
{
"method": "tools/call",
"params": {
"name": "send-draft",
"arguments": {
"inbox_id": "inbox_123",
"draft_id": "draft_987654321"
}
}
}
send-draft sends the draft as it is, so it does not accept field overrides at send time. To change a pending or failed draft, call update-draft first, and to discard one so it is never sent, call delete-draft. A draft that was already sent, is being sent, or was discarded answers 409 validation_error with "Only a pending or failed draft can be sent." If the draft's inputs are no longer valid at send time (for example, if the sender domain has lost verification since drafting), expect the API to reject the send and surface the error in the terminal. Call get-draft again to check the draft's state, and confirm the exact error codes in the API reference.
Integrating file uploads into email workflows
Agents often need to send invoices, reports, or log files. The send.io API accepts attachments as Base64-encoded strings in the JSON payload. Base64 encoding increases size by approximately 33% (a 4:3 ratio), and MIME line wrapping adds further overhead that brings the total to roughly 36-37%, so a 10 MB file becomes about 13.3 to 13.7 MB in the payload. The documented limit is a 40 MB whole message as sent, with attachments Base64 encoded like any other content. Batch sends do not accept attachments at all.
Required fields for email attachments
The attachments array contains objects with filename, content (Base64 string), and content_type (MIME type; send.io detects it from the content when you leave it out). For example, a CSV report:
{
"attachments": [
{
"filename": "report.csv",
"content": "ZGF0YSx2YWx1ZQo...",
"content_type": "text/csv"
}
]
}
Email payload limits and file types
send.io's documented whole-message limit is 40 MB as sent, with attachments Base64 encoded like any other content. Gmail and other providers typically cap messages at 25 MB MIME-encoded, which allows roughly 18-19 MB of raw binary data once Base64 inflation of about one-third is counted. If you exceed the limit, expect a payload-size error before delivery is attempted (commonly a 413 Payload Too Large, though you should confirm the exact code in the API reference). For large files, consider uploading to storage and sending a link instead of an attachment.
Code example: sending email attachments
Full send-email tool call with an attachment (the attachment field names follow the documented Send email schema, so check them against your server's schema):
{
"method": "tools/call",
"params": {
"name": "send-email",
"arguments": {
"from": "agent@yourdomain.com",
"to": "user@example.com",
"subject": "Monthly Report",
"text": "Please find the report attached.",
"attachments": [
{
"filename": "report.pdf",
"content": "JVBERi0xLjQKJ...",
"content_type": "application/pdf"
}
]
}
}
}
Diagnostic patterns: how Claude reports email failures
Production agents must fail loudly. The send.io API surfaces errors as JSON with a statusCode, name, and message, and the codes below are from the documented error table, not guesses. A timeout is a client- or network-level condition and typically surfaces as a 408 or 504 rather than a documented API code. Once you know the codes, you can retry on 429, alert on 403, and validate input on 400 and 422.
Error name | Typical HTTP status | Meaning | Fix |
|---|---|---|---|
| 422 | A field has the wrong type or format, such as a malformed recipient address | Validate email format and payload fields before sending |
| 403 | Not allowed, for example sending from a domain that is not verified | Verify the domain's DKIM, SPF, and return path records before sending |
| 403 | Sending is suspended for the workspace because of its sending reputation | Request review. Suspension is lifted manually after it passes |
| 429 | More than 10 requests per second for your team | Back off and retry. Spread requests over time |
| 402 | The credit balance is too low to send; nothing was sent | Buy credits in Billing before retrying |
| 409 | An | Use a new key |
| 409 | A request with the same | Retry later to receive the original response |
Error names and status codes are illustrative. Confirm the exact codes in the API reference.
Debugging email send timeouts
If the MCP server does not respond within your client's configured timeout, you receive a timeout error, often surfaced as a 408 or 504. The default timeout and how to adjust it depend on your MCP client, so check the Claude Code documentation for the current setting. The message may still deliver if the request reached the server. To prevent duplicates on retry, include an Idempotency-Key header with a unique UUID. The server stores this key for 24 hours, and a retry with the same key returns the original result without sending a duplicate email.
Handling invalid recipient email errors
An invalid-recipient error (a 422 validation_error for a field with the wrong type or format) indicates the to field contains a malformed address. This check happens at the API level before any SMTP conversation. Claude Code displays the validation error, allowing you to correct the address format. This immediate feedback prevents the silent failure mode where a message appears to send but bounces later.
Handling unverified sender domains
An unverified-domain error (a 403 validation_error naming an unverified domain) means you are attempting to send from a domain that has not completed DNS verification. The fix is to add the required DKIM and SPF records in the send.io dashboard. Until verification completes, the API rejects all sends from that domain. This hard stop prevents your agent from sending email that would fail DMARC alignment and damage your sender reputation.
Handling 429 rate limit responses
The API reference documents a team-wide limit of more than 10 requests per second, and a 429 means the account is healthy and busy rather than unavailable. Back off and retry later; continuing to hammer a rate-limited API exacerbates the problem and risks account suspension. Implement a circuit breaker in your agent loop that halts execution and alerts after repeated failures, with a common threshold of five consecutive failures, and treat 429 responses separately from hard failures like timeouts and 5xx errors.
Debugging partial payload failures
Batch sends through POST /emails/batch are validated strictly by default: the whole batch fails on the first invalid email. Passing the x-batch- validation: permissive header sends the valid emails and returns an errors array of { index, error } entries for the rest, so parse that response to identify which recipients were sent and which need follow-up. A cc or bcc failure does not necessarily fail the primary to delivery, so check per- recipient results where the endpoint provides them. Note that batch items cannot carry attachments.
Provision an agent inbox and connect it to Claude Code using the quickstart guide.
FAQs
How do you send email from Claude Code without writing a script?
Connect the send.io MCP server to Claude Code, then prompt: "Send an email to [address] with subject [subject] and body [body]." Claude makes the tool call directly without generating code.
Can Claude send email to multiple recipients at once?
Yes. A single send accepts 1 to 50 addresses in the to field (a string or an array) and supports cc and bcc. For many separate messages, the documented path is batch sending through POST /emails/batch, up to 100 emails per request, with no attachments. Check the credits documentation for how your plan meters usage.
Does the MCP server retry failed sends automatically?
No. The caller controls retries. Use an Idempotency-Key header to prevent duplicates when retrying failed requests.
How do you verify a sender domain before sending?
Add the domain in the send.io dashboard, then add the DKIM, SPF, and return path DNS records. Verification completes when DNS propagates, and propagation time depends on your DNS provider and the TTL on your records.
What happens if Claude makes a malformed tool call?
The MCP server returns a validation error (illustratively a 400) listing the missing or invalid fields. Claude Code surfaces this error in the terminal immediately.
Key terms glossary
MCP (Model Context Protocol): A standard for exposing tools to AI assistants like Claude Code over JSON-RPC 2.0, enabling structured communication between agents and external systems.
Tool call: A structured request an agent makes to an external system with a defined schema and response contract, replacing free-form code generation with deterministic execution.
Scoped API key: A credential limited to specific permissions and resources, so a compromised key cannot access the full account or other inboxes.
Idempotency key: A client-generated header stored for 24 hours that prevents duplicate sends when a request is retried, ensuring safe retry logic.
Rate limit (429): An HTTP response indicating the caller exceeded the allowed request rate, accompanied by a Retry-After header specifying when to resume.
Circuit breaker: A control pattern that halts agent execution when a failure threshold is reached, preventing runaway loops from exhausting quotas or budgets.