Source: https://cli.nylas.com/guides/send-email-from-terminal

# 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](https://cli.nylas.com/authors/aaron-de-mello) Senior Engineering Manager

Reviewed by [Caleb Geene](https://cli.nylas.com/authors/caleb-geene)

Updated May 2, 2026

> **TL;DR:** Install Nylas CLI (`brew install nylas/nylas-cli/nylas`), authenticate once, then send email with `nylas email send --to user@example.com`. Works with Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP. No sendmail, no Postfix, no SMTP config.

## 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](https://workspaceupdates.googleblog.com/2023/09/winding-down-google-sync-and-less-secure-apps-support.html), and [Microsoft retired Basic Auth for Exchange Online in October 2022](https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/deprecation-of-basic-authentication-exchange-online). 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](https://developers.google.com/identity/protocols/oauth2#expiration)), 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](https://developers.google.com/identity/protocols/oauth2), 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

```bash
# 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@latest
```

## 2. Authenticate your mailbox

Head to [dashboard-v3.nylas.com](https://dashboard-v3.nylas.com/), create an application, and connect your mailbox. Then grab your API key and run:

```bash
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`](https://cli.nylas.com/docs/commands/auth-config) stores credentials in your system keyring. You can verify the connection at any time:

```text
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 keyring
```

## 3. Send an email

```bash
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:

```text
✓ Email sent successfully

  Message ID: abc123def456
  To: jamie@example.com
  Subject: Deployment complete
  Sent at: 2026-03-25T15:30:00-04:00
```

## 4. Read and search your inbox

```bash
# 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 --mime
```

Add `--json` to any list command for structured output you can pipe into `jq` or feed to an agent:

```bash
nylas email list --limit 1 --json
```

```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

```bash
# 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

```bash
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_clicked
```

## 7. Sign and encrypt with GPG

No extra tools needed. If you have GPG installed, the CLI signs and encrypts natively using [RFC 3156](https://www.rfc-editor.org/rfc/rfc3156) PGP/MIME:

```bash
# 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 --verify
```

See the full [GPG encrypted email guide](https://cli.nylas.com/guides/gpg-encrypted-email-cli) for key management, troubleshooting, and multi-recipient encryption.

## 8. AI-powered smart compose

```bash
# 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 levels
```

## 9. Scripting and automation

Every command supports `--json` output, so you can pipe it into `jq`, your agent, or any other tool:

```bash
# 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.csv
```

## 10. Pipe to AI agents

The CLI is designed for composability. Pipe JSON output to any agent running in your terminal:

```bash
# 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-code
```

[Model Context Protocol (MCP)](https://modelcontextprotocol.io/) lets AI assistants call CLI tools directly. See the full [AI agent email access guide](https://cli.nylas.com/guides/ai-agent-email-mcp) 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.

```bash
# 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
```

```bash
# 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
fi
```

## 12. 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 |

> **Update (February 18, 2026)**: Corrected install instructions and fixed the agent-send example to include required email send fields (`--subject`, `--body`, and `--yes`).

## Next steps

- [Send Outlook email from the CLI](https://cli.nylas.com/guides/send-outlook-email-cli) -- Microsoft 365 and Exchange-specific send patterns
- [Send Yahoo Mail from the CLI](https://cli.nylas.com/guides/send-yahoo-email-cli) -- skip app-specific passwords and SMTP config
- [Send iCloud Mail from the CLI](https://cli.nylas.com/guides/send-icloud-email-cli) -- custom domains, Hide My Email, no app passwords
- [Send email from PowerShell](https://cli.nylas.com/guides/send-email-powershell) -- PowerShell-specific patterns, scheduling, and scripting
- [List Gmail emails](https://cli.nylas.com/guides/list-gmail-emails) -- read and search your Gmail inbox from the terminal
- [List Exchange emails](https://cli.nylas.com/guides/list-exchange-emails) -- Exchange Online and on-prem before EWS deprecation
- [List IMAP emails](https://cli.nylas.com/guides/list-imap-emails) -- Fastmail, Zoho, self-hosted, and ISP email
- [Manage your calendar from the terminal](https://cli.nylas.com/guides/manage-calendar-from-terminal) -- events, scheduling, timezone tools
- [Receive inbound email](https://cli.nylas.com/guides/receive-inbound-email-cli) -- managed addresses and webhooks
- [Full command reference](https://cli.nylas.com/docs/commands) -- every flag and subcommand documented
