Back to Blog
/4 min read/By SMTPfast Team

How to Send Email From an OpenAI Agents SDK Agent (MCP, With Approval)

Connect the agent to an email API's hosted MCP server with MCPServerStreamableHttp, pass your API key in a header, keep only the tools the job needs with a tool filter, and set require_approval on send_email so the run stops before each send until a person approves it. The full Python script is below; we ran it against the SMTPfast MCP server with openai-agents 0.26.0 on 28 November 2026.

ai-agentsmcppythonopenaitutorial
Share:𝕏in

The short answer: connect the agent to an email API's hosted MCP server, give it only the tools it needs, and make send_email need approval. The run then stops before each send, and a person says yes or no.

The script below does all three. We ran it against the SMTPfast MCP server on 28 November 2026 with openai-agents 0.26.0, using a scripted model in place of the OpenAI call: the read tools ran, the run stopped at send_email, and a rejected send was not sent. We build SMTPfast; any email API with a Streamable HTTP MCP server works the same way.

For everything SMTPfast offers agents on one page (the MCP server, inboxes, drafts a person approves, REST and SMTP), see email API for AI agents.

What you need

  • Python 3.10 or later and pip install openai-agents.
  • An OPENAI_API_KEY for the model.
  • An SMTPfast account with a verified sending domain, and an API key with the scopes the agent needs: email:send, email:read and domain:read for this example. Create it under API keys in the dashboard; the free plan works.

The script

# pip install openai-agents
import asyncio
import os

from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp, create_static_tool_filter


async def main():
    async with MCPServerStreamableHttp(
        name="smtpfast",
        params={
            "url": "https://smtpfa.st/api/mcp",
            "headers": {"Authorization": f"Bearer {os.environ['SMTPFAST_API_KEY']}"},
        },
        cache_tools_list=True,
        client_session_timeout_seconds=30,
        # Show the model only the tools this job needs.
        tool_filter=create_static_tool_filter(
            allowed_tool_names=["get_capabilities", "list_domains", "check_before_send", "send_email", "get_email"]
        ),
        # Pause the run before every send.
        require_approval={"always": {"tool_names": ["send_email"]}},
    ) as smtpfast:
        agent = Agent(
            name="Mailer",
            instructions="You send short, plain emails with the SMTPfast tools. Send only from [email protected].",
            mcp_servers=[smtpfast],
        )

        result = await Runner.run(agent, "Email [email protected] that the nightly backup finished.")

        while result.interruptions:
            state = result.to_state()
            for item in result.interruptions:
                print(f"{item.name} {item.arguments}")
                if input("Send it? [y/N] ").strip().lower() == "y":
                    state.approve(item)
                else:
                    state.reject(item)
            result = await Runner.run(agent, state)

        print(result.final_output)


asyncio.run(main())
export SMTPFAST_API_KEY=sf_...
export OPENAI_API_KEY=sk-...
python mailer.py

What you see when it runs:

send_email {"from": "[email protected]", "to": "[email protected]", "subject": "...", "text": "..."}
Send it? [y/N]

Before it gets there, the agent usually calls list_domains or check_before_send. Those run without a question, because they only read.

How the pieces work

  • MCPServerStreamableHttp is the SDK's client for remote MCP servers. Your process connects to https://smtpfa.st/api/mcp and calls the tools; the API key stays in your process.
  • tool_filter decides which tools the model sees. The SMTPfast server has 109 tools; this agent needs five. A short list costs fewer tokens and leaves the model fewer wrong choices.
  • require_approval turns a call to send_email into an interruption. Runner.run returns with result.interruptions set; you approve or reject each item on result.to_state() and run again with that state. A rejected call is reported to the model as not approved, and nothing goes to the API.
  • client_session_timeout_seconds=30 gives a slow tool call more time than the default of 5 seconds.

The SDK also has HostedMCPTool, where OpenAI's servers call the MCP server for you. Then your API key goes to OpenAI with each request. The local client above keeps it on your side.

Make it safer

  1. Scope the key. The agent can do anything its key allows. For a notifications agent, email:send and domain:read are enough. Create keys under API keys; a key can never create other keys with more access than itself.
  2. Draft instead of send. For replies to people, give the agent save_inbox_draft instead of send_email, and a key with inbound:read but no email:send. The server then refuses any send, and a person sends the draft from the dashboard. See how to build an AI agent that answers support email.
  3. Check before sending. check_before_send tests the sender domain, the content and the links, and returns what to fix. Put "call check_before_send first" in the instructions.
  4. Treat email content as data. If the agent reads mail or web pages, they can contain instructions. Keep approval on for every tool that sends, and do not approve sends you did not expect.

Need the whole API?

If one agent needs most of the API, use the compact endpoint https://smtpfa.st/api/mcp/compact instead. It has two tools, search_api and call_api, in place of the full list, and costs about 650 tokens of tool definitions instead of about 34,000. Every operation then goes through call_api, so require_approval on call_api asks before every call, reads included. We measured the trade-off in 109 MCP tools vs 2.

Sources

Checked on 28 November 2026:

Frequently asked questions

How do I let an OpenAI Agents SDK agent send email?

Connect it to an email API's MCP server. With SMTPfast: create MCPServerStreamableHttp with url https://smtpfa.st/api/mcp and an Authorization header with your API key, then pass it to Agent(mcp_servers=[...]). The agent gets tools such as send_email, list_domains and check_before_send.

How do I make the agent ask before it sends an email?

Set require_approval on the MCP server, for example {"always": {"tool_names": ["send_email"]}}. Runner.run then returns with result.interruptions instead of sending. Turn the result into a state with result.to_state(), call state.approve(item) or state.reject(item) for each one, and pass the state back to Runner.run. A rejected send never reaches the email API.

The SMTPfast MCP server has over 100 tools. Do I send all of them to the model?

No. Use tool_filter=create_static_tool_filter(allowed_tool_names=[...]) so the model sees only the tools the job needs. Fewer tools use fewer tokens and leave the model fewer wrong choices. If the agent needs the whole API, use https://smtpfa.st/api/mcp/compact, which exposes two tools (search_api and call_api) in place of the full list.

Can the agent send from any address?

No. SMTPfast sends only from domains your team has verified, so an agent cannot send as a domain you do not own. Within your verified domains, say in the instructions which address to use, and use an API key with only the scopes the agent needs.

Ready to get started?

Start sending transactional email today. Free to start, no credit card required.

Start free