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.
Install
# macOS / Linux
brew install nylas/nylas-cli/nylas
# Windows PowerShell
irm https://cli.nylas.com/install.ps1 | iex
New to the CLI? The getting started guide covers setup in under a minute.
Authenticate
nylas auth login
nylas auth whoami
# => Authenticated as you@company.com (Google Workspace)
Works with Gmail, Outlook, Exchange, Yahoo, iCloud, and any IMAP server. No provider-specific config needed.
Extract the latest OTP
nylas otp get
# => ✓ Found code: 847291 (from noreply@github.com, 23s ago)
# => Copied to clipboard
That's it. The CLI scans your recent emails for verification codes, extracts the digits, and copies to clipboard.
Scripting and CI/CD
Use --raw to output just the code — no formatting, no clipboard:
CODE=$(nylas otp get --raw)
echo "OTP is: $CODE"
This makes it easy to pipe into Playwright tests, Cypress, or any CI/CD pipeline:
# In a GitHub Actions workflow
- name: Get verification code
run: |
CODE=$(nylas otp get --raw --timeout 30)
echo "OTP=$CODE" >> $GITHUB_ENV
For PowerShell environments, see the CI/CD email testing guide which covers GitHub Actions and Azure DevOps with Pester assertions.
Watch mode — poll for incoming codes
When you trigger a signup or password reset and need to wait for the code to arrive:
nylas otp watch --interval 5
# Polls every 5 seconds, prints each new code as it arrives
This is useful for automated E2E email testing where you trigger a password reset flow in Playwright, then wait for the OTP to land.
Filter by sender
If you're getting codes from multiple services simultaneously:
nylas otp get --from "noreply@github.com"
nylas otp get --from "verify@stripe.com"
How it works under the hood
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:
- List Gmail Emails from the Command Line
- List Outlook Emails from Terminal
- Read and Search Email in PowerShell
Use case: AI agent account signups
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:
nylas mcp install --assistant claude-code
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
Compared to rolling your own
| Feature | Gmail API + regex | IMAP polling | Nylas CLI |
|---|---|---|---|
| Setup time | Hours (OAuth, scopes, parsing) | Hours (IMAP config, TLS) | 1 minute |
| Multi-provider | No (Gmail only) | Partial | Yes (6 providers) |
| OTP extraction | Manual regex | Manual regex | Built-in |
| Clipboard copy | Manual | Manual | Automatic |
| CI/CD friendly | Complex | Complex |
--raw flag |
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
Related guides:
- 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
All guides: cli.nylas.com/guides
Top comments (0)