> ## Documentation Index
> Fetch the complete documentation index at: https://ahasend.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> AhaSend stores all message data in the EU. See /facts.
> The API base URL is https://api.ahasend.com. Send the API key in the Authorization: Bearer header. See /api-reference/authentication.
> Use send.ahasend.com for SMTP. Ports 25, 587 and 2525 use STARTTLS. Port 465 is not supported. See /smtp.
> For send-only integrations, create an API Key v2 under Credentials → Add and scope it to messages:send:{your-domain}. See /send-api/credentials and /api-reference/scopes.

# ahasend messages: Send and Track Email

> Send transactional email from your terminal with the AhaSend CLI: text/HTML, attachments, templates, scheduling, sandbox mode, and batch sends from CSV/JSON.

AhaSend CLI `messages` commands let you send, inspect and cancel email messages; this page covers their arguments and flags.

Before running the examples, [log in with a full API key](/docs/cli/authentication), use your verified sender domain, and replace `YOUR_RESOURCE_ID` with a resource UUID from your test account. Create any named template, recipient, attachment, or JSON files first. Shell examples use Bash; examples that read JSON with `jq` need jq installed. Sends use sandbox mode.

## Overview

```text theme={null}
ahasend messages [subcommand] [flags]
```

Available subcommands:

* `send` - Send email messages
* `list` - List sent messages
* `get` - Get details for one message
* `cancel` - Cancel scheduled messages

## Send Messages

### Basic Usage

```bash theme={null}
# Text email
ahasend messages send --sandbox \
  --from sender@example.com \
  --to recipient@example.com \
  --subject "Hello" \
  --text "Hello World"

# HTML email
ahasend messages send --sandbox \
  --from sender@example.com \
  --to recipient@example.com \
  --subject "Welcome" \
  --html "<h1>Welcome!</h1><p>Thank you for signing up.</p>"
```

### Recipients

```bash theme={null}
# Single recipient
ahasend messages send --sandbox \
  --from sender@example.com \
  --to user@example.com \
  --subject "Notification" \
  --text "Your order has been processed"

# Multiple recipients
ahasend messages send --sandbox \
  --from sender@example.com \
  --to user1@example.com \
  --to user2@example.com \
  --subject "Team Update" \
  --text "Important announcement"

# Batch from file
ahasend messages send --sandbox \
  --from sender@example.com \
  --recipients users.csv \
  --subject "Newsletter" \
  --html-template newsletter.html
```

### Content Options

```bash theme={null}
# With template
ahasend messages send --sandbox \
  --from sender@example.com \
  --to recipient@example.com \
  --subject "Welcome {{name}}" \
  --html-template welcome.html \
  --global-substitutions data.json

# With attachments
ahasend messages send --sandbox \
  --from sender@example.com \
  --to recipient@example.com \
  --subject "Invoice" \
  --text "Please find your invoice attached." \
  --attach invoice.pdf

# Scheduled delivery
ahasend messages send --sandbox \
  --from sender@example.com \
  --to recipient@example.com \
  --subject "Reminder" \
  --text "Meeting tomorrow at 2 PM" \
  --schedule "<RFC3339 time within the next 7 days>"
```

### Testing

```bash theme={null}
# Sandbox mode (no actual sending)
ahasend messages send \
  --from test@example.com \
  --to test@example.com \
  --subject "Test" \
  --text "Testing" \
  --sandbox
```

## List Messages

```bash theme={null}
# List recent messages
ahasend messages list

# With filters
ahasend messages list --limit 50 --status delivered
```

## Get a Message

```bash theme={null}
ahasend messages get YOUR_RESOURCE_ID
```

Attachments are limited to 10 MB per file by the CLI. Scheduling uses RFC3339, in the future and within 7 days. Sandbox outcomes are `deliver`, `bounce`, `defer`, `fail`, and `suppress`; see [sandbox mode](/docs/send-api/sandbox).

## Cancel Messages

```bash theme={null}
# Cancel scheduled message
SCHEDULE=$(python3 -c 'from datetime import datetime,timedelta,timezone; print((datetime.now(timezone.utc)+timedelta(hours=1)).isoformat())')
TEST_ID=$(ahasend messages send --sandbox --from sender@yourdomain.com --to test@example.com --subject "Cancellation test" --text "Test" --schedule "$SCHEDULE" --output json | jq -er '.data[0].id | ltrimstr("<") | split("@")[0]')
ahasend messages cancel "$TEST_ID"
```

Use the message UUID for get and cancel commands. If sending returns an ID such as `<UUID@yourdomain.com>`, extract the UUID as shown above.

## Advanced Usage

For detailed information on batch processing and templating:

* [Batch Processing Guide](/docs/cli/batch-processing) - High-volume email sending
* [Template System](/docs/cli/templates) - MiniJinja templates with Jinja2-compatible syntax
* [Examples](/docs/cli/examples) - Real-world use cases

## Next Steps

* [Learn about domains](/docs/cli/commands/domains)
* [Configure webhooks](/docs/cli/commands/webhooks)
* [View statistics](/docs/cli/commands/stats)

## Command Flags

These flags come from the current CLI. All commands also accept the [global flags](/docs/cli/configuration#global-flags).

### `messages cancel`

| Flag | Description and default |
| - | - |
| `--force` | Skip confirmation prompt |

### `messages get`

This command has no command-specific flags. See [global flags](/docs/cli/configuration#global-flags).

### `messages list`

| Flag | Description and default |
| - | - |
| `--cursor string` | Pagination cursor for next page |
| `--from-time string` | Filter messages created after this time (RFC3339 or relative like '24h', '7d') |
| `--limit int` | Maximum number of messages to return (1-100) (default 100) |
| `--message-id string` | Filter by message ID header |
| `--recipient string` | Filter by recipient email address |
| `--sender string` | Sender email address (must be from your domain) |
| `--show-details` | Show detailed message information |
| `--status strings` | Filter by message status (can be used multiple times) |
| `--subject string` | Filter by subject text (partial match) |
| `--tags strings` | Filter by tags (can be used multiple times) |
| `--to-time string` | Filter messages created before this time (RFC3339 or relative) |

### `messages send`

| Flag | Description and default |
| - | - |
| `--amp string` | AMP HTML content |
| `--amp-template string` | AMP HTML template file path |
| `--attach strings` | Attachment file paths (can be used multiple times, max 10MB per file) |
| `--from string` | Sender email address (required) |
| `--global-substitutions string` | JSON file with global template variables |
| `--header strings` | Custom headers in format 'Header-Name: value' (can be used multiple times) |
| `--html string` | HTML content |
| `--html-template string` | HTML template file path |
| `--idempotency-key string` | Idempotency key for duplicate prevention |
| `--max-concurrency int` | Maximum concurrent sends for batch operations (default 1) |
| `--max-retries int` | Maximum retry attempts for failed sends (default 3) |
| `--progress` | Show progress bar for batch operations (disabled in debug mode) |
| `--recipients string` | Recipients file (JSON or CSV format) with per-recipient substitutions |
| `--sandbox` | Send in sandbox mode (for testing) |
| `--sandbox-result string` | Sandbox result simulation: deliver, bounce, defer, fail, or suppress (only used with --sandbox) (default "deliver") |
| `--schedule string` | Schedule delivery time in RFC3339 format (e.g., '`RFC3339_TIMESTAMP`') |
| `--show-metrics` | Show performance metrics after batch operations |
| `--subject string` | Email subject |
| `--tags strings` | Tags for categorization (can be used multiple times) |
| `--text string` | Plain text content |
| `--text-template string` | Plain text template file path |
| `--to strings` | Recipient email addresses (can be used multiple times) |
| `--track-clicks` | Enable click tracking (default true) |
| `--track-opens` | Enable open tracking (default true) |

## Related Guides

* [Install the CLI](/docs/cli/installation), [CLI authentication](/docs/cli/authentication), [Sending guide](/docs/send-api/send-email).
* [SMTP settings](/docs/smtp), [Node.js SDK](/docs/guides/nodejs-sdk), [Go SDK](/docs/guides/go-sdk).
* [CLI configuration and output](/docs/cli/configuration), [API authentication](/docs/api-reference/authentication), [Permission scopes](/docs/api-reference/scopes).
* [Domain setup](/docs/domains), [Sandbox behavior](/docs/send-api/sandbox), [Tracking setup](/docs/tracking/open-tracking).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.