DEV Community

SandMail
SandMail

Posted on

How to Extract OTP Codes with AI Agents — One API Call

How to Extract OTP Codes with AI Agents — One API Call

Every AI agent hits the same wall: email verification. 80% of online services require an OTP to sign up. Your agent can fill forms, click buttons, solve captchas — but it can't check an inbox.

I built SandMail to fix this. One API call creates a disposable inbox, waits for the verification email, and returns the OTP code.

3 Lines of Code (JavaScript)

import { SandMail } from 'sandmail';
const client = new SandMail('sk_live_your_key');

const inbox = await client.createInbox();
const otp = await client.waitForOTP(inbox.email, { timeout: 30 });
console.log(otp.code);       // "847291"
console.log(otp.confidence); // "high"
Enter fullscreen mode Exit fullscreen mode

Python Version

from sandmail import SandMail

client = SandMail("sk_live_your_key")
inbox = client.create_inbox()
otp = client.wait_for_otp(inbox.email, timeout=30)
print(otp.code)  # "847291"
Enter fullscreen mode Exit fullscreen mode

How OTP Extraction Works

The API parses the email body using pattern matching across 15 languages — no AI model needed, just fast regex.

Supported formats:

  • "Your verification code is 847291" → ✅ high confidence
  • "Code: 4829" → ✅ high confidence
  • "Ihr Bestätigungscode lautet 847291" (German) → ✅ high confidence
  • "验证码:847291" (Chinese) → ✅ high confidence
  • Magic links → ✅ detected

Each result includes code, type, confidence, and verification_links.

Real-time with Webhooks

For production pipelines, use webhooks. The OTP is extracted and included directly in the webhook payload:

{
  "event": "message.received",
  "data": {
    "recipient": "agent_x7k@tempyx.com",
    "has_otp": true,
    "otp": {
      "code": "847291",
      "confidence": "high"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

MCP Server for Claude & Cursor

If you use Claude Code or Cursor, install the MCP server:

npm install -g sandmail-mcp
Enter fullscreen mode Exit fullscreen mode

Then ask your agent: "Create a temporary email and get me the verification code from Twitter."

Why Not Gmail API?

  • Gmail: 250 sends/day limit, OAuth2 complexity, no disposable inboxes
  • SandMail: unlimited inboxes, one API key, OTP extracted automatically

Try It

Free tier: 500 requests/month, no credit card.

Happy to answer any questions!

Top comments (0)