Guide
List Your Exchange Emails from the Command Line
Microsoft Exchange access traditionally requires Exchange Web Services (EWS), PowerShell cmdlets, or the Microsoft Graph API — each with their own authentication complexity. The Nylas CLI handles OAuth2 and Exchange's auth flow behind the scenes — authenticate once, then list, search, and read emails with a single command.
The problem with Exchange access
Accessing Exchange email programmatically means choosing between EWS (deprecated for Exchange Online), PowerShell's Get-MailboxFolderPermission (requires admin modules), or the Microsoft Graph API (requires Azure app registration and permission scoping). None of these give you a simple command-line workflow.
On-premises Exchange adds further complexity with autodiscover configuration, NTLM authentication, and certificate management. Most developers just want to read their inbox without becoming an Exchange admin.
1. Install the Nylas CLI
# macOS / Linux (Homebrew)
brew install nylas/nylas-cli/nylas
# Or build from source (requires Go 1.23+)
go install github.com/nylas/cli/cmd/nylas@latest2. Connect your Exchange account
Head to dashboard-v3.nylas.com, create an application, and connect your Exchange or Exchange Online account. Then grab your API key:
nylas auth config
# Paste your API key when prompted
# Verify the connection
nylas auth whoami
# => Authenticated as you@company.com (Exchange)3. List your emails
# List recent emails
nylas email list
# Limit results
nylas email list --limit 10
# Only unread emails
nylas email list --unread4. Search and filter
# Search by keyword
nylas email search "budget approval" --limit 5
# Search by sender
nylas email search "from:cfo@company.com"
# Search within a date range
nylas email search "after:2026-01-01 before:2026-02-01"5. Read a specific email
# Read an email by ID (IDs are shown in list output)
nylas email read msg_abc123
# Read the raw MIME source
nylas email read msg_abc123 --mime6. JSON output for scripting
Every command supports --json output, so you can pipe it into jq, a script, or an AI agent:
# Count unread emails
nylas email list --unread --json | jq length
# Extract subjects
nylas email list --limit 5 --json | jq '.[].subject'Filter distribution list emails with a quick script:
# Filter internal distribution list emails
nylas email list --json \
| jq '[.[] | select(.to[]?.email | test("all-staff|engineering"; "i"))]' \
| jq length \
| xargs -I{} echo "Distribution list emails: {}"7. Exchange Online vs on-premises
The Nylas CLI works with both Exchange Online (Microsoft 365) and on-premises Exchange Server. The authentication flow is the same — Nylas handles autodiscover, EWS fallback, and token management transparently.
- Exchange Online — OAuth2 via Microsoft identity platform, no admin consent required for personal mailbox access
- Exchange Server (on-prem) — connects via EWS with autodiscover, supports NTLM and basic auth
8. EWS vs Nylas CLI
Here is what it takes to list emails with each approach:
| Step | Exchange Web Services (EWS) | Nylas CLI |
|---|---|---|
| Setup | Configure autodiscover, EWS endpoint URL | nylas auth config |
| Authentication | NTLM, Basic, or OAuth2 with Azure AD app | OAuth2 via Nylas dashboard |
| Code | SOAP XML requests or EWS Managed API (~50 lines) | Zero code |
| List emails | FindItem SOAP operation | nylas email list |
| Pagination | Manage IndexedPageItemView offset manually | --limit flag |
| Search | AQS or restriction filters in SOAP XML | nylas email search |
| Deprecation risk | EWS deprecated for Exchange Online (Oct 2026) | Nylas migrates automatically |
| On-prem support | Yes | Yes |
9. Shared mailboxes and distribution lists
Exchange environments commonly use shared mailboxes and distribution lists. Here is how to work with them:
# Connect a shared mailbox as a separate grant in the Nylas dashboard,
# then switch between grants:
nylas email list --grant "shared-mailbox@company.com"
# Search across distribution list emails
nylas email search "to:engineering@company.com" --limit 10
nylas email search "to:all-staff@company.com" --limit 10
# Filter by specific Exchange folders
nylas folder list
nylas email list --folder "Inbox"
nylas email list --folder "Sent Items"10. EWS deprecation and migration
Microsoft is deprecating Exchange Web Services (EWS) for Exchange Online, with the shutdown scheduled for October 2026. This affects any tool or script that connects to Exchange Online via EWS.
- If you use EWS scripts today — they will stop working for Exchange Online after the deprecation date. The Nylas CLI is not affected because Nylas handles the migration to Microsoft Graph transparently.
- If you use on-premises Exchange — EWS continues to work for on-prem Exchange Server. No migration needed for on-prem deployments.
- If you are building new integrations — start with the Nylas CLI or API to avoid the EWS migration entirely. Nylas abstracts the provider protocol, so you are insulated from future Microsoft API changes.
Next steps
- Send email from the terminal
- List Gmail emails — same workflow for Google
- List Outlook emails — same workflow for Outlook.com and Microsoft 365
- List Yahoo Mail emails — same workflow for Yahoo
- List iCloud Mail emails — same workflow for Apple
- List IMAP emails — works with Fastmail, Zoho, and more
- Give AI agents email access via MCP
- Full command reference