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_KEYfor the model. - An SMTPfast account with a verified sending domain, and an API key with the scopes the agent needs:
email:send,email:readanddomain:readfor 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
MCPServerStreamableHttpis the SDK's client for remote MCP servers. Your process connects tohttps://smtpfa.st/api/mcpand calls the tools; the API key stays in your process.tool_filterdecides 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_approvalturns a call tosend_emailinto an interruption.Runner.runreturns withresult.interruptionsset; you approve or reject each item onresult.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=30gives 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
- Scope the key. The agent can do anything its key allows. For a notifications agent,
email:sendanddomain:readare enough. Create keys under API keys; a key can never create other keys with more access than itself. - Draft instead of send. For replies to people, give the agent
save_inbox_draftinstead ofsend_email, and a key withinbound:readbut noemail: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. - Check before sending.
check_before_sendtests the sender domain, the content and the links, and returns what to fix. Put "call check_before_send first" in the instructions. - 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:
- OpenAI Agents SDK: MCP and human in the loop, and the
openai-agents0.26.0 source for the parameter names - SMTPfast: MCP server docs, API keys
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 freeRelated Posts
How to Build an AI Agent That Answers Support Email (A Person Approves Each Reply)
Put an inbox on your support address, subscribe a webhook to new mail, and let your code ask a model for a reply and save it as a draft in the thread. The agent's API key can read mail and write drafts but cannot send, so a person reviews and sends every reply. This guide has the full Node.js handler (about 70 lines), the keys to create, and the checks that keep an email from steering the agent.
Can ChatGPT Send Email? How to Connect It to an Email API With MCP
Yes, on ChatGPT Business, Enterprise and Edu. You add an email API's MCP server as a custom MCP server in ChatGPT on the web, sign in with OAuth, and ChatGPT can then send email from your own verified domain, asking you to confirm each send. Pro accounts can connect custom MCP servers only for read and fetch actions, so they cannot send this way. Checked on 28 November 2026.