← All use cases
OTP

OTP Verification

Auto-extract and verify 2FA/MFA confirmation codes

MailBrew's unique OTP auto-extraction API automatically parses verification codes from email bodies. No regex needed. Supports 6-digit codes, alphanumeric codes, magic links, and other major OTP patterns.

Why MailBrew for this use case

01

One-call OTP extraction

Dedicated endpoint /emails/{id}/otp auto-extracts verification codes from email body. No regex writing required.

02

Multiple format support

Auto-recognizes 6-digit numeric, alphanumeric, magic links, and other major OTP patterns.

03

2FA/MFA test automation

Fully automate two-factor authentication in login flows. No manual code entry needed.

04

Security requirement validation

Perfect for testing OTP expiration, resend limits, brute-force protection, and other security requirements.

Sample code

Python

Python
from mailbrew import MailBrew

client = MailBrew("mb_your_key_here")

# 1. Create a test address
addr = client.create_address(ttl=300)

# 2. Trigger login in app → sends OTP email
trigger_login(email=addr["address"])

# 3. Auto-extract OTP (no regex needed!)
email = client.wait_for_email(addr["address"], timeout=30)
otp = client.extract_otp(addr["address"], email["id"])
print(otp)  # => "847291"

# 4. Complete login with extracted OTP
complete_login(code=otp)

Ready to try this use case?

Get started with the free plan today. No credit card required.

Create free account →