> ## Documentation Index
> Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
> Use this file to discover all available pages before exploring further.

# AgentMailChannel Quickstart

> Run agents in an AgentMail email thread that people can read and reply to

`AgentMailChannel` turns a conversation into one email thread in an [AgentMail](https://agentmail.to) inbox. Every post is emailed to the people you choose, and their replies join the conversation the agents read next. It uses the AgentMail API, so there is no mail server to configure.

Reference: [AgentMailChannel](https://docs.swarms.world/api/channels/agentmail-channel.md).

## Setup

1. Create an inbox at [agentmail.to](https://agentmail.to), for example `research@agentmail.to`.
2. Create an API key and export it:

```bash theme={null}
export AGENTMAIL_API_KEY="..."
```

## Two agents email you

```python theme={null}
from swarms import Agent, AgentMailChannel

channel = AgentMailChannel(
    inbox_id="research@agentmail.to",
    to="you@example.com",
    subject="EV battery market report",
)

researcher = Agent(
    agent_name="Researcher",
    system_prompt="You gather facts and figures. Answer in a short bullet list.",
    model_name="gpt-5.4",
    max_loops=1,
    channel=channel,
)
writer = Agent(
    agent_name="Writer",
    system_prompt="You turn the facts in the conversation into a short report.",
    model_name="gpt-5.4",
    max_loops=1,
    channel=channel,
)

task = "Report on the EV battery market."
researcher.run(task)
writer.run(task)

for message in channel.messages():
    print(f"\n## {message['agent_name']}\n{message['content']}")

channel.close()
```

## A person approves before the work continues

```python theme={null}
import time

from swarms import Agent, AgentMailChannel

channel = AgentMailChannel(
    inbox_id="launch@agentmail.to",
    to="pm@yourco.com",
    subject="Launch plan for review",
)

planner = Agent(
    agent_name="Planner",
    system_prompt="You write launch plans and revise them from feedback.",
    model_name="gpt-5.4",
    max_loops=1,
    channel=channel,
)
planner.run("Draft a launch plan for our new analytics product.")

while not any(m["agent_name"] == "pm@yourco.com" for m in channel.messages()):
    time.sleep(30)

planner.run("Finalise the plan using the PM's reply.")
channel.close()
```

The PM's reply is read back under their address, using AgentMail's extracted text, so the quoted history is left out.

## A GroupChat debate in your inbox

Each message that wins a turn is one email in the thread.

```python theme={null}
from swarms import Agent, AgentMailChannel, GroupChat


def speaker(name, stance):
    return Agent(
        agent_name=name,
        system_prompt=f"You argue for {stance}. Keep each message short.",
        model_name="gpt-5.4",
        max_loops=1,
    )


chat = GroupChat(
    agents=[
        speaker("Optimist", "the benefits"),
        speaker("Pessimist", "the risks"),
        speaker("Realist", "a balanced view"),
    ],
    max_loops=6,
    channel=AgentMailChannel(
        inbox_id="debates@agentmail.to",
        to=["you@example.com", "team@example.com"],
        subject="Should hospitals adopt AI for triage?",
    ),
)
chat.run("Should hospitals adopt AI for triage?")
```

## A ConcurrentWorkflow sends every view

```python theme={null}
from swarms import Agent, AgentMailChannel, ConcurrentWorkflow

angles = ["technology", "regulation", "supply chain"]

workflow = ConcurrentWorkflow(
    agents=[
        Agent(
            agent_name=f"{angle.title().replace(' ', '-')}-Analyst",
            system_prompt=f"Analyse the task from the {angle} angle only.",
            model_name="gpt-5.4",
            max_loops=1,
        )
        for angle in angles
    ],
    channel=AgentMailChannel(
        inbox_id="research@agentmail.to",
        to="you@example.com",
        subject="EV battery outlook: three angles",
    ),
)
workflow.run("What will shape the EV battery market over the next five years?")
```

The thread gets the task, then one email per analyst in agent order once the parallel step completes.

## Pick up the thread later

```python theme={null}
saved = channel.thread_id

later = AgentMailChannel(
    inbox_id="launch@agentmail.to",
    to="pm@yourco.com",
    thread_id=saved,
)
later.messages()
```

For the EU region, pass `base_url="https://api.agentmail.eu"`.

## Tips

* **Each read is an API call.** An agent reads the whole thread on every run.
* **Treat replies as untrusted input.** Anyone who replies on the thread adds to what the agents read.

## Next steps

* [SmtpChannel](https://docs.swarms.world/examples/channels/smtp-channel.md), the same pattern with a mailbox you already run
* [Channels with every structure](https://docs.swarms.world/examples/channels/multi-agent-structures.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.