Guide
List Your Outlook Emails from the Command Line
The Microsoft Graph API requires Azure app registration, permission scoping, and token management just to read your own inbox. The Nylas CLI handles OAuth2 and Microsoft's auth flow behind the scenes — authenticate once, then list, search, and read emails with a single command.
The problem with Microsoft Graph API
To list Outlook emails programmatically, you need to register an app in Azure AD, configure API permissions, handle token refresh, and write code against the Microsoft Graph REST API or SDK. That is a lot of plumbing to read your own inbox.
The az CLI does not have email commands. PowerShell's Get-MailboxFolderPermission requires Exchange Online management modules and admin access. Neither gives you a clean, portable command-line workflow.
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 Outlook account
Head to dashboard-v3.nylas.com, create an application, and connect your Microsoft 365 or Outlook.com 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 (Microsoft)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 "quarterly report" --limit 5
# Search by sender
nylas email search "from:manager@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 Microsoft notifications with a quick script:
# Filter Teams notifications
nylas email list --json \
| jq '[.[] | select(.from[0].email | test("teams|sharepoint"; "i"))]' \
| jq length \
| xargs -I{} echo "Microsoft notifications: {}"7. Work with Outlook folders and categories
Outlook uses a traditional folder hierarchy plus a category system for color-coded organization. The Nylas CLI maps both:
# List emails in a specific folder
nylas email list --folder "Inbox"
nylas email list --folder "Sent Items"
nylas email list --folder "Drafts"
# List all available folders
nylas folder list
# Filter by common Outlook folders
nylas email list --folder "Archive"
nylas email list --folder "Junk Email"8. Microsoft Graph API vs Nylas CLI
Here is what it takes to list emails with each approach:
| Step | Microsoft Graph API | Nylas CLI |
|---|---|---|
| Register app | Azure AD app registration | Not required |
| Permissions | Configure Mail.Read scope, admin consent for org | Handled by Nylas dashboard |
| Auth flow | Implement MSAL token acquisition, handle refresh | nylas auth config |
| Code | REST calls or Microsoft Graph SDK, ~40 lines minimum | Zero code |
| List emails | GET /me/messages with auth headers | nylas email list |
| Pagination | Handle @odata.nextLink manually | --limit flag |
| Search | $search or $filter OData query params | nylas email search |
| Rate limits | Handle 429 responses and retry-after headers | Handled automatically |
9. Microsoft 365 tips
A few things to know when using the Nylas CLI with Microsoft 365 and Outlook.com accounts:
- Shared mailboxes — connect the shared mailbox directly as a separate grant in the Nylas dashboard
- Delegated access — if you have delegate access to another user's mailbox, connect it as a separate grant
- Conditional access policies — if your org enforces device compliance or IP restrictions, the Nylas connection may need to be allowlisted by your IT admin
- Teams and SharePoint notifications — these arrive as regular emails and can be filtered with
nylas email search "from:noreply@email.teams.microsoft.com"
Next steps
- Send email from the terminal — send, schedule, and track emails
- List Gmail emails — same workflow for Google
- 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
- List Exchange emails — same workflow for Exchange
- Give AI agents email access via MCP — connect Claude, Cursor, or VS Code to your inbox
- Full command reference — every flag and subcommand documented