Tools: Extract OTP Codes from Email — Skip the Inbox - Full Analysis

Tools: Extract OTP Codes from Email — Skip the Inbox - Full Analysis

Install

Authenticate

Extract the latest OTP

Scripting and CI/CD

Watch mode — poll for incoming codes

Filter by sender

How it works under the hood

Use case: AI agent account signups

Compared to rolling your own Every OTP interrupts your flow. You get a login prompt, switch to your email client, wait for the message, find the 6-digit code buried in a template, type it in, switch back. That's 30-60 seconds of context switching per authentication event. For developers running integration tests or E2E flows, it's worse. You need the code programmatically, which means writing custom email polling logic for each provider — Gmail API, Microsoft Graph, IMAP idle — before you can even get to the actual test. Nylas CLI solves both problems with one command: nylas otp get. New to the CLI? The getting started guide covers setup in under a minute. Works with Gmail, Outlook, Exchange, Yahoo, iCloud, and any IMAP server. No provider-specific config needed. That's it. The CLI scans your recent emails for verification codes, extracts the digits, and copies to clipboard. Use --raw to output just the code — no formatting, no clipboard: This makes it easy to pipe into Playwright tests, Cypress, or any CI/CD pipeline: For PowerShell environments, see the CI/CD email testing guide which covers GitHub Actions and Azure DevOps with Pester assertions. When you trigger a signup or password reset and need to wait for the code to arrive: This is useful for automated E2E email testing where you trigger a password reset flow in Playwright, then wait for the OTP to land. If you're getting codes from multiple services simultaneously: The CLI fetches your last 10 unread emails via the Nylas API, scans subject lines and bodies for common OTP patterns (6-digit codes, "verification code", "security code", etc.), and returns the most recent match. No regex to maintain, no IMAP polling logic to write. For a deeper look at how email listing works, see: AI coding agents like Claude Code and Cursor often need to sign up for services on your behalf. They hit the email verification step and get stuck. With MCP email access, your agent can extract OTPs directly: Now Claude Code can call nylas otp get --raw as a tool to complete signups autonomously. See the full AI agent email setup guide for MCP configuration. For more on why AI agents need email access: Why AI Agents Need Email For a full comparison of CLI email tools, see Best CLI Email Tools Compared. Full guide with watch mode, filtering, and automation examples: Extract OTP Codes from Email All guides: cli.nylas.com/guides Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

# macOS / Linux -weight: 500;">brew -weight: 500;">install nylas/nylas-cli/nylas # Windows PowerShell irm https://cli.nylas.com/-weight: 500;">install.ps1 | iex # macOS / Linux -weight: 500;">brew -weight: 500;">install nylas/nylas-cli/nylas # Windows PowerShell irm https://cli.nylas.com/-weight: 500;">install.ps1 | iex # macOS / Linux -weight: 500;">brew -weight: 500;">install nylas/nylas-cli/nylas # Windows PowerShell irm https://cli.nylas.com/-weight: 500;">install.ps1 | iex nylas auth login nylas auth whoami # => Authenticated as [email protected] (Google Workspace) nylas auth login nylas auth whoami # => Authenticated as [email protected] (Google Workspace) nylas auth login nylas auth whoami # => Authenticated as [email protected] (Google Workspace) nylas otp get # => ✓ Found code: 847291 (from [email protected], 23s ago) # => Copied to clipboard nylas otp get # => ✓ Found code: 847291 (from [email protected], 23s ago) # => Copied to clipboard nylas otp get # => ✓ Found code: 847291 (from [email protected], 23s ago) # => Copied to clipboard CODE=$(nylas otp get --raw) echo "OTP is: $CODE" CODE=$(nylas otp get --raw) echo "OTP is: $CODE" CODE=$(nylas otp get --raw) echo "OTP is: $CODE" # In a GitHub Actions workflow - name: Get verification code run: | CODE=$(nylas otp get --raw --timeout 30) echo "OTP=$CODE" >> $GITHUB_ENV # In a GitHub Actions workflow - name: Get verification code run: | CODE=$(nylas otp get --raw --timeout 30) echo "OTP=$CODE" >> $GITHUB_ENV # In a GitHub Actions workflow - name: Get verification code run: | CODE=$(nylas otp get --raw --timeout 30) echo "OTP=$CODE" >> $GITHUB_ENV nylas otp watch --interval 5 # Polls every 5 seconds, prints each new code as it arrives nylas otp watch --interval 5 # Polls every 5 seconds, prints each new code as it arrives nylas otp watch --interval 5 # Polls every 5 seconds, prints each new code as it arrives nylas otp get --from "[email protected]" nylas otp get --from "[email protected]" nylas otp get --from "[email protected]" nylas otp get --from "[email protected]" nylas otp get --from "[email protected]" nylas otp get --from "[email protected]" nylas mcp -weight: 500;">install --assistant claude-code nylas mcp -weight: 500;">install --assistant claude-code nylas mcp -weight: 500;">install --assistant claude-code - List Gmail Emails from the Command Line - List Outlook Emails from Terminal - Read and Search Email in PowerShell - E2E Email Testing with Playwright - Send Email from the Command Line - Give Your AI Agent an Email Address - Build an AI Email Triage Agent - Monitor Your Inbox with PowerShell - Secure Email Handling for CLI - Manage Calendar from the Terminal