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

# Gmail CLI: Send Gmail from Command Line

Use a Gmail CLI to send Gmail from command line scripts without creating a Google Cloud project, wiring Gmail API client code, configuring SMTP passwords, or running Postfix locally. The same send command supports CC/BCC, scheduled delivery, tracking, JSON output, and provider-neutral automation.

Written by [Qasim Muhammad](https://cli.nylas.com/authors/qasim-muhammad) Staff SRE

Reviewed by [Qasim Muhammad](https://cli.nylas.com/authors/qasim-muhammad)

Updated May 16, 2026

> **TL;DR:** Install Nylas CLI, authenticate once, then run `nylas email send --to user@example.com --subject "Hello" --body "Hi" --yes`. This sends Gmail over HTTPS through the Nylas API, not through a local SMTP server.

## How do you send Gmail from command line?

To send Gmail from command line scripts, connect your Gmail or Google Workspace account once, then use [`nylas email send`](https://cli.nylas.com/docs/commands/email-send) with 4 email fields: recipient, subject, body, and confirmation. For a Gmail CLI send email workflow, that replaces Gmail API setup, SMTP credential storage, and local mail transfer agent configuration.

The traditional paths are heavier than the job. Google's [Gmail API sending guide](https://developers.google.com/workspace/gmail/api/guides/sending) routes sends through `messages.send` or `drafts.send`, and the [users.messages.send reference](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages/send) expects a MIME message in the request body. Gmail SMTP requires app-password or OAuth-aware SMTP tooling, plus port 465 or 587 access. For Google Workspace, Google's [less secure apps shutdown notice](https://workspaceupdates.googleblog.com/2023/09/winding-down-google-sync-and-less-secure-apps-support.html) ended password-only third-party access, so old username/password scripts are not a durable path. Linux mail tools like `mailx`, `sendmail`, or Postfix also need a relay before they can deliver anything outside the machine.

The CLI keeps the local surface to one binary and one command. Authentication and provider routing happen through the Nylas API, while the terminal command stays stable across Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP.

## 1. Install the CLI

On macOS or Linux, Homebrew is the fastest install path and usually completes in under 60 seconds. Windows users can use the PowerShell installer from the [getting started guide](https://cli.nylas.com/guides/getting-started).

```bash
brew install nylas/nylas-cli/nylas
```

Verify the binary is available before wiring it into scripts:

```bash
nylas --version
```

## 2. Connect Gmail once

Create a Nylas application, connect your Gmail or Google Workspace mailbox through hosted OAuth, then save the API key locally. The setup is 2 steps after account creation: connect the mailbox and run `nylas auth config`. The CLI stores configuration under `~/.config/nylas/` and uses your system credential store for secrets where available.

Start at [dashboard-v3.nylas.com](https://dashboard-v3.nylas.com/register?utm_source=https%3A%2F%2Fcli.nylas.com%2F&utm_medium=website&utm_campaign=cli&utm_id=cli), connect Gmail, then configure the CLI:

```bash
nylas auth config
# Paste your API key when prompted

nylas auth whoami
# => Authenticated as you@gmail.com (Google)
```

Use [`nylas auth whoami`](https://cli.nylas.com/docs/commands/auth-whoami) before scheduled jobs to confirm the active grant is the Gmail account you expect.

## 3. Send a Gmail message

A basic Gmail send requires 1 recipient, 1 subject, 1 body, and `--yes` for non-interactive execution. Without `--yes`, the CLI prompts for confirmation before sending.

```bash
nylas email send \
  --to "friend@example.com" \
  --subject "Quick update" \
  --body "Hi - sharing the notes from today." \
  --yes
```

This is the command to use from Bash, zsh, cron, GitHub Actions, Docker containers, and AI agent subprocesses when the task is just send Gmail from terminal without setting up SMTP.

## 4. Add CC, BCC, and multiple recipients

The send command accepts 3 recipient controls: repeated `--to` values, plus separate `--cc` and `--bcc` flags. Keep automated sends paced and targeted so Gmail does not classify the mailbox as bulk or suspicious.

```bash
nylas email send \
  --to "alice@example.com" \
  --to "bob@example.com" \
  --cc "manager@example.com" \
  --bcc "archive@example.com" \
  --subject "Design review" \
  --body "Please review the proposal before Friday." \
  --yes
```

## 5. Schedule, track, and log sends

Scheduled sending lets the Nylas API queue the Gmail message server-side for a future delivery time. Tracking flags add open and link tracking when that is appropriate for the workflow. JSON output returns a structured response that can be logged by scripts.

```bash
# Schedule delivery
nylas email send \
  --to "client@example.com" \
  --subject "Follow-up" \
  --body "Checking in on the proposal." \
  --schedule "tomorrow 9am" \
  --yes

# Track opens and links
nylas email send \
  --to "lead@example.com" \
  --subject "Resources" \
  --body "Here are the links we discussed." \
  --track-opens --track-links --track-label "gmail-cli" \
  --yes

# Capture the message ID
nylas email send \
  --to "ops@example.com" \
  --subject "Job finished" \
  --body "Nightly job completed." \
  --json --yes | jq -r '.id'
```

## Gmail SMTP vs Gmail API vs CLI

Gmail SMTP is useful for legacy mail clients, but scripts need credential storage, TLS configuration, 2 relay ports, and error parsing. Gmail API is better for application code, but it still requires OAuth client setup, scopes, token refresh, and request handling. A CLI is the shortest path when the operator already has a Gmail account connected and wants repeatable terminal commands.

| Need | Gmail SMTP | Gmail API | Nylas CLI |
| --- | --- | --- | --- |
| Local SMTP server | Sometimes | No | No |
| Google Cloud project | No | Yes | No client project for CLI usage |
| Token refresh code | Tool-dependent | Yes | Handled by Nylas |
| Non-interactive send | Yes, after setup | Yes, after code | `--yes` |
| Structured output | No | Yes | `--json` |
| Cross-provider reuse | No | No | Same command surface |

## Use Gmail sends in scripts

For CI alerts, cron reports, release notifications, and AI agent actions, build the command with 3 variables: recipient, subject, and body. Keep the body in a file or heredoc. The CLI sends the resolved string; your script owns templating and pacing.

```bash
#!/usr/bin/env bash
set -euo pipefail

recipient="team@example.com"
subject="Deploy complete: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
body="$(cat ./deploy-summary.txt)"

nylas email send \
  --to "$recipient" \
  --subject "$subject" \
  --body "$body" \
  --json --yes | jq -r '.id'
```

## Troubleshooting Gmail command-line sends

Most Gmail command-line send failures fall into 3 buckets: wrong active mailbox, missing non-interactive confirmation, or blocked SMTP assumptions from older scripts. Check the active grant first, add `--yes` for automation, and remember that the CLI uses HTTPS instead of SMTP ports.

### The message sends from the wrong Gmail account

Run [`nylas auth list`](https://cli.nylas.com/docs/commands/auth-list) and [`nylas auth whoami`](https://cli.nylas.com/docs/commands/auth-whoami) to confirm the active grant. If you have multiple Gmail accounts connected, switch to the expected grant before running the send job.

### The command waits for confirmation

Add `--yes` for non-interactive scripts. Cron, CI, Docker, and AI agent subprocesses should always include this flag so the process does not wait forever at a confirmation prompt.

### SMTP ports are blocked

The CLI send path uses HTTPS to the Nylas API, so blocked SMTP ports 25, 465, and 587 do not stop the command. This is why the same flow works in locked-down sandboxes and CI networks where direct Gmail SMTP is unavailable.

## Next steps

- [Send email from Linux command line without SMTP](https://cli.nylas.com/guides/send-email-from-terminal) - the broader cross-provider terminal send guide
- [Gmail CLI: List Gmail Emails from Terminal](https://cli.nylas.com/guides/list-gmail-emails) - read and search Gmail from the same CLI
- [Gmail API pagination and sync](https://cli.nylas.com/guides/gmail-api-pagination-sync) - nextPageToken, maxResults, and historyId explained
- [Gmail API quotas in 2026](https://cli.nylas.com/guides/gmail-api-quotas-2026) - method costs and quota-aware agent patterns
- [Email CLI tools compared](https://cli.nylas.com/guides/best-cli-email-tools-compared) - Nylas CLI, mailx, mutt, msmtp, and swaks
- [Full command reference](https://cli.nylas.com/docs/commands) - every flag and subcommand documented
