CrewAI is one of the most capable frameworks for building teams of cooperating AI agents. You can define roles, goals, and backstories, assign tools, and let agents collaborate on complex multi-step tasks. But there is one category of task that every CrewAI team fails at the same point: email verification. Without an inbox, your crew cannot sign up for, verify, or access any of the 80% of web services that require email confirmation.
Adding Email Tools to a CrewAI Agent
CrewAI's tool system makes it straightforward to add AgentMailr capabilities to any agent. You define two tools — one to create an inbox, one to wait for an OTP — and the agent can use them as part of its normal task execution.
import agentmailr
from crewai_tools import tool
client = agentmailr.Client(api_key=os.environ["AGENTMAILR_API_KEY"])
@tool("Create Email Inbox")
def create_inbox(username: str) -> dict:
"""Create a new email inbox for receiving verification emails.
Returns the inbox ID and email address."""
inbox = client.inboxes.create(username=username)
return {"id": inbox.id, "address": inbox.address}
@tool("Wait for OTP")
def wait_for_otp(inbox_id: str, timeout_seconds: int = 30) -> str:
"""Wait for an OTP verification code to arrive in the inbox.
Returns the extracted OTP code as a string."""
result = client.messages.wait_for_otp(
inbox_id=inbox_id,
timeout=timeout_seconds * 1000
)
return result.otp
@tool("Delete Inbox")
def delete_inbox(inbox_id: str) -> bool:
"""Delete an email inbox after use."""
client.inboxes.delete(inbox_id)
return True
A Real Multi-Agent Workflow
Consider a crew tasked with researching and trialing developer tools in a given category. The workflow requires three agents working in sequence:
- Research Agent: searches the web, identifies the top 5 tools in the category, returns their signup URLs and free tier details
- Signup Agent: navigates to each signup page, creates accounts using programmatic inboxes, completes email verification for each
- Evaluation Agent: logs into each verified account, explores the free tier, evaluates features against defined criteria, returns a comparison report
Without email tools, the Signup Agent is blocked. It can fill out the form but cannot verify. With AgentMailr tools, the entire workflow runs autonomously from start to finish.
Parallel Signups Without Collisions
When a CrewAI crew runs multiple agents in parallel — say, five Signup Agents each handling one tool — each agent must have its own inbox. Sharing an inbox across parallel agents causes OTP routing collisions: Agent 1 receives Agent 3's verification code, the wrong account gets verified, and the failure is silent.
The fix is simple: each agent calls create_inbox at the start of its task and stores the inbox ID in its task context. No shared state. Each agent's OTP goes to its own inbox. Parallel signups work correctly by default.
from crewai import Agent, Task, Crew
signup_agent = Agent(
role="Account Registration Specialist",
goal="Create verified accounts on web services autonomously",
backstory="""You are an expert at navigating web signup flows.
You always create a dedicated email inbox for each signup,
use it to receive verification codes, and delete it when done.""",
tools=[create_inbox, wait_for_otp, delete_inbox, browser_tool],
verbose=True,
)
signup_task = Task(
description="""Sign up for {service_name} at {signup_url}.
1. Create a fresh email inbox
2. Fill the signup form with the inbox address
3. Wait for the verification OTP
4. Complete verification
5. Store the credentials and delete the inbox""",
agent=signup_agent,
expected_output="Verified account credentials and session state",
)
crew = Crew(agents=[signup_agent], tasks=[signup_task])
result = crew.kickoff(inputs={"service_name": "Notion", "signup_url": "..."})
Start Free
Add AgentMailr to your CrewAI stack and unlock the full web for your agents. Free to start, no credit card required.