Guide
Send Email from the Terminal
Most command-line email tools require a local SMTP relay (Postfix, sendmail) or only work with one provider. Nylas CLI sends email from Linux, macOS, and Windows terminals across 6 providers — Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP — with 72+ commands, built-in OAuth2, and zero SMTP configuration. Setup takes under 2 minutes.
Written by Aaron de Mello Senior Engineering Manager
Reviewed by Caleb Geene
Why is sending email from the command line hard?
The mail command has shipped on Unix systems since 1977, and mailx since the early 1980s — but neither supports OAuth2. That's a problem: Google disabled “less secure app” passwords for Gmail in September 2024, and Microsoft retired Basic Auth for Exchange Online in October 2022. If your CLI tool doesn't handle OAuth2 token refresh (Gmail access tokens expire every 3,600 seconds per Google's OAuth 2.0 documentation), it can't reliably send email through these providers.
The Nylas CLI bypasses all of this. It talks directly to the Nylas API, which handles OAuth2 token refresh, provider abstraction, and connection management. Authenticate once with a single command, then all 72+ commands work across Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP on any platform.
1. Install
# 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. Authenticate your mailbox
Head to dashboard-v3.nylas.com, create an application, and connect your mailbox. Then grab your API key and run:
nylas auth config
# Paste your API key when prompted
# Verify it works
nylas auth whoami
# => Authenticated as you@company.com (Google Workspace)Running nylas auth config stores credentials in your system keyring. You can verify the connection at any time:
Authentication Status
Current Account:
Email: dev@example.com
Provider: google
Grant ID: d3f4a5b6-c7d8-9e0f-a1b2-c3d4e5f6g7h8
Status: ✓ Valid
Configuration:
Region: us
Config Path: /home/dev/.config/nylas/config.yaml
Secret Store: system keyring3. Send an email
nylas email send \
--to "colleague@company.com" \
--subject "Quarterly report attached" \
--body "Hi -- please review the Q4 numbers before Friday."
# Skip the confirmation prompt
nylas email send --to user@example.com --subject "Quick note" --body "..." --yes
# CC and BCC
nylas email send \
--to alice@team.com \
--cc bob@team.com \
--bcc manager@team.com \
--subject "Sprint update" \
--body "All tasks on track."After a successful send, the CLI confirms delivery:
✓ Email sent successfully
Message ID: abc123def456
To: jamie@example.com
Subject: Deployment complete
Sent at: 2026-03-25T15:30:00-04:004. Read and search your inbox
# List recent emails
nylas email list --limit 10
# Only unread
nylas email list --unread
# Search by keyword
nylas email search "invoice" --limit 5
# Read a specific message
nylas email read msg_abc123
# Read the raw MIME source
nylas email read msg_abc123 --mimeAdd --json to any list command for structured output you can pipe into jq or feed to an agent:
nylas email list --limit 1 --json[
{
"id": "a1b2c3d4e5f6g7h8",
"grant_id": "d3f4a5b6-c7d8-9e0f-a1b2-c3d4e5f6g7h8",
"thread_id": "a1b2c3d4e5f6g7h8",
"subject": "Re: Project Atlas — Q2 launch timeline",
"from": [{"name": "Sarah Chen", "email": "sarah@example.com"}],
"to": [{"name": "Alex Rivera", "email": "alex@example.com"}],
"snippet": "The staging environment is ready. I've attached the test results from Friday's run...",
"date": "2026-03-25T14:22:18-04:00",
"unread": true,
"starred": false,
"folders": ["INBOX"],
"object": "message"
}
]5. Schedule emails for later
# Send in 2 hours
nylas email send --to team@company.com --subject "Reminder" --body "..." --schedule 2h
# Send tomorrow morning
nylas email send --to team@company.com --subject "Standup" --body "..." --schedule "tomorrow 9am"
# Send on a specific date
nylas email send --to client@example.com --subject "Follow-up" --body "..." --schedule "2026-03-01 14:30"6. Track opens and clicks
nylas email send \
--to prospect@company.com \
--subject "Proposal attached" \
--body "Here is our proposal for Q2." \
--track-opens \
--track-links \
--track-label "q2-outreach"
# Tracking events are delivered via webhooks:
nylas webhook create \
--url https://your-server.com/hooks \
--triggers message.opened,message.link_clicked7. Sign and encrypt with GPG
No extra tools needed. If you have GPG installed, the CLI signs and encrypts natively using RFC 3156 PGP/MIME:
# Sign with your GPG key
nylas email send --to legal@partner.com --subject "Contract" --body "..." --sign
# Encrypt with recipient's public key (auto-fetched from keyservers)
nylas email send --to legal@partner.com --subject "Contract" --body "..." --encrypt
# Both (recommended for maximum security)
nylas email send --to legal@partner.com --subject "Contract" --body "..." --sign --encrypt
# Decrypt and verify a received message
nylas email read msg_xyz789 --decrypt --verifySee the full GPG encrypted email guide for key management, troubleshooting, and multi-recipient encryption.
8. AI-powered smart compose
# Generate a draft from a prompt
nylas email smart-compose --prompt "Thank them for the meeting and confirm next steps"
# Generate a reply to a specific message
nylas email smart-compose --message-id msg_abc123 --prompt "Accept the invitation politely"
# AI inbox analysis
nylas email ai analyze --unread
# => Summary, categories, action items, urgency levels9. Scripting and automation
Every command supports --json output, so you can pipe it into jq, your agent, or any other tool:
# Morning inbox summary script
#!/bin/bash
echo "=== Inbox Summary ==="
unread=$(nylas email list --unread --json | jq length)
echo "Unread: $unread"
# Urgent check
nylas email list --unread --json \
| jq '[.[] | select(.subject | test("urgent|asap"; "i"))]' \
| jq 'length' \
| xargs -I{} echo "Urgent: {}"
# Bulk send from a CSV
while IFS=, read -r email name; do
nylas email send \
--to "$email" \
--subject "Hello $name" \
--body "Your account is ready." \
--yes
sleep 2
done < contacts.csv10. Pipe to AI agents
The CLI is designed for composability. Pipe JSON output to any agent running in your terminal:
# Agent triages your inbox
nylas email list --unread --json | agent triage --rules ./inbox-rules.yml
# Agent drafts a reply, CLI sends it
nylas email send \
--to sarah@team.io \
--subject "Re: Follow-up" \
--body "$(agent draft --context msg_a1f2)" \
--yes
# Start the built-in MCP server for Claude, Cursor, or VS Code
nylas mcp install --assistant claude-codeModel Context Protocol (MCP) lets AI assistants call CLI tools directly. See the full AI agent email access guide for MCP setup and tool configuration.
11. Cron jobs, here-docs, and shell-native automation
This guide is the Unix-style hub page in the cluster. The PowerShell and Outlook pages focus on Windows automation and Microsoft-specific behavior. This one is where shell-native workflows matter: cron jobs, here-doc templating, pipes, exit codes, and small composable scripts you can run on Linux, macOS, or a remote box over SSH.
# Use a here-doc for longer email bodies in shell scripts
nylas email send \
--to ops@company.com \
--subject "Nightly backup report" \
--body "$(cat <<'EOF'
Backups completed successfully.
- Cluster: prod-a
- Duration: 18m
- Snapshot age: 24h
EOF
)" \
--yes# Cron-friendly check with explicit exit handling
if ! nylas email send --to alerts@company.com --subject "Disk warning" --body "Disk usage > 90%" --yes; then
echo "email send failed" >&2
exit 1
fi12. mailx, sendmail, and Postfix replacement
Another reason this page exists separately is migration pressure from classic Unix mail tools. Teams still have scripts built around mail, mailx, sendmail, or local Postfix relays. Those workflows are operationally different from the Outlook-specific and PowerShell-specific pages because the pain point is usually MTA maintenance, not OAuth app registration.
If you are replacing an old shell script that once piped text into mailx, the right mental model is not "API integration." It is "drop-in command-line sending without keeping a local mail stack alive."
How does Nylas CLI compare to other CLI email tools?
| Feature | mail / mailx | mutt | Nylas CLI |
|---|---|---|---|
| Send email | Yes (needs MTA) | Yes (needs SMTP) | Yes (one command) |
| Read inbox | Local only | Yes | Yes |
| Gmail OAuth2 | No | Complex | Built-in |
| Microsoft 365 | No | Complex | Built-in |
| GPG sign/encrypt | Manual | Built-in | Built-in |
| Calendar access | No | No | Yes |
| JSON output | No | No | Yes (--json) |
| AI compose | No | No | Yes |
| MCP server | No | No | Built-in |
Next steps
- Send Outlook email from the CLI -- Microsoft 365 and Exchange-specific send patterns
- Send Yahoo Mail from the CLI -- skip app-specific passwords and SMTP config
- Send iCloud Mail from the CLI -- custom domains, Hide My Email, no app passwords
- Send email from PowerShell -- PowerShell-specific patterns, scheduling, and scripting
- List Gmail emails -- read and search your Gmail inbox from the terminal
- List Exchange emails -- Exchange Online and on-prem before EWS deprecation
- List IMAP emails -- Fastmail, Zoho, self-hosted, and ISP email
- Manage your calendar from the terminal -- events, scheduling, timezone tools
- Receive inbound email -- managed addresses and webhooks
- Full command reference -- every flag and subcommand documented