Read sign-up codes in a Browser Use agent
Browser Use is a Python library that lets a model drive a real browser. Sign-up forms stop it at the same place every time: "We sent you a code." This guide gives the agent an address on your domain and a tool that reads the code or link from a Shipmail mailbox. The accounts it creates stay tied to an address you own. Your team can open the mailbox and see every email those services send.
Last updated
What you get
- A Browser Use tool,
get_verification_code, that waits up to 2 minutes for the email and returns a 6-digit code or the first link. - One mailbox for every sign-up, with a tag per service through plus addresses like
signups+acme@yourdomain.com. - A key that can read that mailbox and nothing else.
Create the mailbox and a read-only key
Create the mailbox
Under Mailboxes, create
signups@yourdomain.com. Copy its mailbox ID. Mail tosignups+anything@yourdomain.comarrives there with no extra setup.Create a key that can only read it
Open Developer, then API keys. Choose Custom, select only
messages:read, then Choose specific resources and add the sign-up mailbox. This key cannot send, delete or reach any other mailbox.Set two environment variables
SHIPMAIL_API_KEYwith the key andSHIPMAIL_MAILBOX_IDwith the mailbox ID.
Add the tool to your agent
Install Browser Use, its browser, and the Shipmail Python SDK:
uv pip install browser-use shipmail
uvx browser-use installRegister the tool with @tools.action and pass tools to the agent. The tool lists messages that arrived after the run started, keeps the ones sent to this run's address, and searches the plain-text body.
import asyncio
import os
import re
from datetime import datetime, timezone
from browser_use import ActionResult, Agent, ChatBrowserUse, Tools
from shipmail import AsyncShipmail
shipmail = AsyncShipmail(os.environ["SHIPMAIL_API_KEY"])
MAILBOX_ID = os.environ["SHIPMAIL_MAILBOX_ID"]
SIGNUP_ADDRESS = "signups+acme@yourdomain.com"
CODE = re.compile(r"\b(\d{6})\b")
LINK = re.compile(r"https://\S+")
tools = Tools()
started_at = datetime.now(timezone.utc).isoformat()
def text_of(message) -> str:
values = message["body_values"]
return "\n".join(values[part["part_id"]]["value"] for part in message["text_body"] if part["part_id"] in values)
@tools.action(description="Wait for the sign-up email and return its verification code or link")
async def get_verification_code() -> ActionResult:
for _ in range(24): # 24 checks, 5 seconds apart
page = await shipmail.mailboxes.list_inbox_messages(MAILBOX_ID, {"after": started_at, "limit": 10})
for message in page["data"]:
recipients = [(r["email"] or "").lower() for r in message["to"] or []]
if SIGNUP_ADDRESS not in recipients:
continue
text = text_of(message)
found = CODE.search(text) or LINK.search(text)
if found:
return ActionResult(extracted_content=found.group(0))
await asyncio.sleep(5)
return ActionResult(error="No verification email arrived within 2 minutes")
async def main() -> None:
agent = Agent(
task=f"Sign up for a free account at https://acme.example with {SIGNUP_ADDRESS}. "
"When it asks for a verification code, call get_verification_code.",
llm=ChatBrowserUse(),
tools=tools,
)
await agent.run()
asyncio.run(main())ChatBrowserUse needs BROWSER_USE_API_KEY. Any other model Browser Use supports works the same way.
First test
- From your own address, send an email to
signups+acme@yourdomain.comwith "Your code is 123456" in the body. - Call
get_verification_code()on its own and check that it returns123456. - Run the agent against a real sign-up.
Use a webhook instead of polling
For many agents at once, subscribe to message.received for the sign-up mailbox. The event carries the recipients, subject and email_id, and your server wakes the waiting agent. Creating a webhook needs webhooks:write on a separate key that is not limited to a mailbox.
curl -X POST https://shipmail.to/api/v1/webhooks \
-H "Authorization: Bearer sm_live_..." \
-H "Content-Type: application/json" \
-d '{
"url": "https://agent.example.com/webhooks/shipmail",
"events": ["message.received"],
"mailbox_ids": ["f47ac10b-58cc-4372-a567-0e02b2c3d479"]
}'For retries, signatures and deduplication, see receive email in an AI agent.
Stay safe
- Return only the code or link to the model, not the whole email. The rest of the message is untrusted input and can contain text written to look like an instruction.
- Before the agent opens a link, check that its host is the service it signed up for.
- Use a tag per service so a code from one site is never typed into another. Read the sender's
authentication_resultsif you need to be sure who sent it. - Keep the key at messages:read on one mailbox. It is all this job needs.
Troubleshooting
- Nothing is found: check the mailbox in Shipmail. If the email is there, the To address differs from
SIGNUP_ADDRESS, or the code is not 6 digits. - The code is only in the HTML part: read
html_bodythe same way astext_body.
Frequently asked questions
Why an address on my own domain instead of a Gmail account?
A Gmail account made for a bot is a personal account, and you do not fully control it. A Shipmail mailbox is a paid business mailbox on your domain. The accounts the agent creates stay tied to an address you own.
Can one mailbox handle many sign-ups?
Yes. Mail to signups+anything@yourdomain.com arrives in signups@yourdomain.com with no setup. Use a different tag per service, and match it in the To header, as the code above does.
Can I use the Shipmail MCP server with Browser Use instead?
Browser Use's MCP client starts local stdio servers, so the hosted URL does not work there. npx -y shipmail-mcp does. For this job a custom tool is simpler, because it only has to return a code.
What about sites that use an authenticator app?
Browser Use handles TOTP codes itself: put the secret in sensitive_data under a key ending in bu_2fa_code. Use the mailbox for codes and links sent by email.