Guide

How AI agents handle email verification and magic links

Find the right verification code or magic link in an agent’s inbox. Handle delayed messages, resends and sender checks with MCP or REST.

A six-digit code is easy to extract. Knowing which registration it belongs to is the part that breaks an automated signup. Resent emails, old messages and a different sender domain can all lead an agent to choose the wrong one.

Agent Loadout has a find_verification_code MCP tool and a REST endpoint for this job. They look in real inbound mail and can wait briefly for a matching message. They do not create codes or bypass the app’s verification process.

Start the clock before submitting the form

Use a test application you control. Enter the agent’s inbox address in its registration form. Immediately before submitting, record an ISO timestamp. Pass that timestamp as since when looking for the mail.

Without a starting point, the lookup checks recent mail from the last 15 minutes. That is convenient for a manual test but it can include a previous registration attempt. If the app issues a new code after a resend, start a new lookup window for that attempt.

Make one lookup

For MCP, ask the client to call find_verification_code with the inbox ID, start time and a subject fragment you expect. It already searches and waits. There is no need to call wait_for_message first.

Example MCP arguments
{
  "inbox_id": "inb_example",
  "since": "2026-10-08T09:00:00Z",
  "subject_contains": "Verify your account",
  "wait": 20
}

Replace the inbox ID and example timestamp with your own values. The equivalent REST request goes to POST /api/v1/inboxes/:id/extract/code. It uses an agent token with email:read.

REST request with your recorded start time
curl --fail-with-body --silent --show-error \
  "https://agent-loadout.com/api/v1/inboxes/$INBOX_ID/extract/code" \
  -H "Authorization: Bearer $AGENT_LOADOUT_TOKEN" \
  -H "Content-Type: application/json" \
  --data "{\"since\":\"$STARTED_AT\",\"wait\":20}"

Set INBOX_ID, AGENT_LOADOUT_TOKEN and STARTED_AT in your shell before running the request. Its response may contain a live code or sign-in link. Keep that output out of shared logs.

Match the registration before using the result

Inspect found first. A false result is a normal outcome when mail has not arrived yet. When it is true, check the matched message and its screening result. A code and a link may both be present.

Only open a returned link if its destination belongs to the application you are signing into. Compare the parsed hostname with a configured allowlist. A string containing the service’s name somewhere in its path is not a match. Avoid following a link merely because the message says it is urgent.

Do not guess the email sender from the website’s domain. A service can send verification mail through a separate domain. The optional from field is a text filter over sender information. It is not proof that a message is authentic.

If an overly narrow filter hides a likely message, the response can report sender_filter_mismatch with candidates. Inspect them. When you change the filters, reuse the original action timestamp so the message you just excluded is still eligible.

Handle waiting as part of the workflow

The lookup can wait for up to 25 seconds. If it returns no match, continue with its cursor as since while keeping the same filters. Put a total deadline around the registration attempt. Two minutes is a reasonable starting point for a test you control; use the app’s actual expiry rules in production.

When the deadline expires, leave a clear failed state for the caller. Repeatedly resubmitting the registration form can generate more emails and invalidate codes that are still in transit. A resend should be a deliberate new attempt.

Email codes and authenticator codes are different resources. For a service that asks for TOTP, use the stored authenticator secret through get_totp_code. The email extraction endpoint cannot calculate that code.

A small test set catches most mistakes

Try the workflow with an old code already in the inbox, delayed delivery and a resend. Add a message from an unexpected sender with a misleading sign-in link. The first three cases should complete or time out predictably. The last should stop for inspection.

Use the events and code extraction reference for the full response fields. Once the account works, store its login using the approach in the credential guide.