mail.app-cli

command module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mail-app-cli

image

A command-line interface for controlling macOS Mail.app. Provides complete scriptable access to accounts, mailboxes, messages, and attachments.

Features

  • See accounts, mailboxes, and unread counts
  • List, read, search, and filter messages
  • Reopen recently handled messages for fast follow-up questions
  • Archive, move, delete, flag, and mark mail
  • Batch message actions with dry-run safety
  • Create, edit, send, and delete drafts
  • Send mail with files and signatures
  • Export messages and attachments for automation
  • Validate exported message JSON before migration work
  • Manage rules and explore smart mailboxes and threads
  • Browse signatures and VIP mail
  • Read Gmail Archive and All Mail reliably
  • Diagnose local Mail Envelope Index access
  • Output scriptable JSON for every workflow

Quick Install

curl -fsSL https://raw.githubusercontent.com/0xSMW/mail.app-cli/master/install.sh | sh

Installation

From Source
go install github.com/0xSMW/mail.app-cli@latest
Build Locally
git clone https://github.com/0xSMW/mail.app-cli.git
cd mail.app-cli
go build -o mail-app-cli

Usage

Accounts

List all Mail.app accounts:

mail-app-cli accounts list

Show details for a specific account:

mail-app-cli accounts show "Gmail"
Mailboxes

List all mailboxes:

mail-app-cli mailboxes list

List mailboxes for a specific account:

mail-app-cli mailboxes list --account "Gmail"
Messages

List messages in a mailbox:

mail-app-cli messages list --account "Gmail" --mailbox "INBOX"

List with filters:

# Show only unread messages
mail-app-cli messages list -a "Gmail" -m "INBOX" --unread

# Show only flagged messages
mail-app-cli messages list -a "Gmail" -m "INBOX" --flagged

# Show messages since a specific date
mail-app-cli messages list -a "Gmail" -m "INBOX" --since "2025-12-01"

# Show messages since a specific date and time
mail-app-cli messages list -a "Gmail" -m "INBOX" --since "2025-12-14 09:00:00"

# Combine filters
mail-app-cli messages list -a "Gmail" -m "INBOX" --unread --since "2025-12-01" --limit 10

Show full message details:

mail-app-cli messages show <message-id> -a "Gmail" -m "INBOX"

Mark message as read/unread:

# Mark as read
mail-app-cli messages mark <message-id> -a "Gmail" -m "INBOX" --read

# Mark as unread
mail-app-cli messages mark <message-id> -a "Gmail" -m "INBOX" --read=false

Flag/unflag a message:

# Flag a message
mail-app-cli messages flag <message-id> -a "Gmail" -m "INBOX" --flagged

# Unflag a message
mail-app-cli messages flag <message-id> -a "Gmail" -m "INBOX" --flagged=false

Archive a message:

mail-app-cli messages archive <message-id> -a "Gmail" -m "INBOX"

Move a message to another mailbox:

mail-app-cli messages move <message-id> "Archive" -a "Gmail" -m "INBOX"

Delete a message:

mail-app-cli messages delete <message-id> -a "Gmail" -m "INBOX"
Sending Email

Send a message:

mail-app-cli send \
  --account "Gmail" \
  --to user@example.com \
  --subject "Hello" \
  --body "Message content here"

Send from a file and append a Mail.app signature:

mail-app-cli send \
  --account "Gmail" \
  --to user@example.com \
  --subject "Hello" \
  --body-file body.md \
  --signature "Work"

Send to multiple recipients:

mail-app-cli send \
  -a "Gmail" \
  -t user1@example.com \
  -t user2@example.com \
  -c cc@example.com \
  -s "Multi-recipient message" \
  --body "Content"

Search for messages across all mailboxes:

mail-app-cli search "important meeting"

Search with limit:

mail-app-cli search "project update" --limit 20

Search uses Mail's local Envelope Index for fast all-mailbox results. If Envelope Index access is blocked by macOS privacy settings, search can fall back to matching recently handled message metadata and prior matching query terms; otherwise, grant Full Disk Access to the app launching mail-app-cli, or use --account and --mailbox for a bounded Mail.app automation fallback.

Force live search and bypass the recent-message shortcut:

mail-app-cli search "project update" --no-cache
Recent Messages

After search, messages show, messages archive, or messages move, the CLI records local recent-message metadata so follow-up questions can avoid rediscovering the same email through a broad mailbox search. The recent journal stores envelope metadata and prior matching query terms, not message bodies.

Search recently handled messages:

mail-app-cli recent search "project update"

Show full details for a recently handled message by ID or query:

mail-app-cli recent show "project update"

Clear the recent-message journal:

mail-app-cli recent clear
Doctor

Check whether the current terminal or automation runner can read Mail's Envelope Index:

mail-app-cli doctor
Attachments

List attachments in a message:

mail-app-cli attachments list <message-id> -a "Gmail" -m "INBOX"

Save an attachment:

mail-app-cli attachments save <message-id> "document.pdf" -a "Gmail" -m "INBOX"

Save to a specific path:

mail-app-cli attachments save <message-id> "document.pdf" -a "Gmail" -m "INBOX" -o ~/Downloads/document.pdf
Batch Operations

Preview a bulk archive:

mail-app-cli messages batch archive -a "Gmail" -m "INBOX" --query "receipt" --dry-run

Preview an exact sender/domain cleanup without shell-side jq filtering:

mail-app-cli messages batch delete -a "Gmail" -m "All Mail" --sender-domain "linkedin.com" --limit 500 --dry-run

Archive message IDs from stdin:

jq -r '.[].id' messages.json | mail-app-cli messages batch archive -a "Gmail" -m "INBOX" --stdin --yes

Move selected messages:

mail-app-cli messages batch move "Receipts" -a "Gmail" -m "INBOX" --query "invoice" --yes

Mark, flag, or delete selected messages:

mail-app-cli messages batch mark -a "Gmail" -m "INBOX" --read=false 123 456
mail-app-cli messages batch flag -a "Gmail" -m "INBOX" --flagged=false --stdin < ids.txt
mail-app-cli messages batch delete -a "Gmail" -m "INBOX" --query "old alert" --dry-run

Run a larger cleanup with chunk progress, read-before-mutate, postcondition checks, and a reusable JSON report:

mail-app-cli messages batch delete \
  -a "Gmail" \
  -m "All Mail" \
  --sender-domain "linkedin.com" \
  --limit 500 \
  --chunk-size 50 \
  --progress \
  --mark-read \
  --verify \
  --report-file ./linkedin-cleanup.json \
  --yes

Before 1.2.0, complex sweeps usually needed separate search, jq, shell loops, manual chunking, and repeated messages list verification. In 1.2.0, the CLI can select exact senders/domains, accept search --no-cache for script compatibility, emit batch progress, write a full result report, mark messages read before archive/delete/move, and include structured verification status in batch output.

Export and Validation

Export messages as JSON:

mail-app-cli export messages -a "Gmail" -m "INBOX" --format json --output inbox.json

Export attachments:

mail-app-cli export attachments -a "Gmail" -m "INBOX" --output ./attachments

Validate an exported message file:

mail-app-cli import messages -a "Gmail" -m "Archive" --format json --file inbox.json --dry-run
Drafts

Create and review a draft:

mail-app-cli drafts create -a "Gmail" --to user@example.com --subject "Review" --body-file body.md
mail-app-cli drafts list -a "Gmail"
mail-app-cli drafts show <draft-id> -a "Gmail"

Send or delete a draft:

mail-app-cli drafts update <draft-id> -a "Gmail" --subject "Updated" --body-file revised.md
mail-app-cli drafts send <draft-id> -a "Gmail"
mail-app-cli drafts delete <draft-id> -a "Gmail" --dry-run
Rules, Smart Mailboxes, Threads, Signatures, and VIP Messages

Inspect higher-level Mail.app surfaces:

mail-app-cli rules list
mail-app-cli smart list
mail-app-cli signatures list
mail-app-cli threads list -a "Gmail" -m "INBOX"
mail-app-cli messages vip --limit 25

Manage supported rule actions:

mail-app-cli rules show "Receipts"
mail-app-cli rules create "Receipts" -a "Gmail" --from-domain stripe.com --move-to Receipts --dry-run
mail-app-cli rules create "Published packages" -a "Gmail" --from-domain support@npmjs.com --subject-contains "Successfully published @example/" --move-to Trash --mark-read --dry-run
mail-app-cli rules enable "Receipts"
mail-app-cli rules disable "Receipts"
mail-app-cli rules delete "Receipts" --dry-run

Preview rule application with normal selectors:

mail-app-cli rules apply "Receipts" -a "Gmail" -m "INBOX" --query "stripe" --dry-run

Inspect smart mailbox, signature, and thread details:

mail-app-cli smart show "Unread Receipts"
mail-app-cli smart query "receipt" --limit 20
mail-app-cli signatures show "Work"
mail-app-cli threads show <thread-id> -a "Gmail" -m "INBOX"
mail-app-cli threads archive <thread-id> -a "Gmail" -m "INBOX" --dry-run
Sync

Trigger sync and get a structured result:

mail-app-cli sync --account "Gmail" --mailbox "INBOX" --wait --json

JSON Output and jq

All commands output JSON format for easy parsing and scripting. The output is formatted with 2-space indentation for human readability while remaining machine-parseable.

Pretty Printing

For even prettier output, pipe through jq:

mail-app-cli accounts list | jq
jq Examples
Filter accounts by email domain
mail-app-cli accounts list | jq '.[] | select(.emailAddress | endswith("@gmail.com"))'
Get only enabled accounts
mail-app-cli accounts list | jq '.[] | select(.enabled==true) | .name'
Count unread messages across all mailboxes
mail-app-cli mailboxes list | jq '[.[].unreadCount] | add'
Find mailboxes with unread messages
mail-app-cli mailboxes list | jq '.[] | select(.unreadCount > 0) | {account, name, unread: .unreadCount}'
Get just the subject lines from messages
mail-app-cli messages list -a "Gmail" -m "INBOX" | jq '.[].subject'
Filter unread messages from specific sender
mail-app-cli messages list -a "Gmail" -m "INBOX" | jq '.[] | select(.read==false and (.sender | contains("boss@company.com")))'
Search and format results as CSV
mail-app-cli search "important" | jq -r '.[] | [.account, .mailbox, .subject, .sender] | @csv'
Count messages by account
mail-app-cli search "project" | jq 'group_by(.account) | map({account: .[0].account, count: length})'
Get attachment names from a message
mail-app-cli attachments list <message-id> -a "Gmail" -m "INBOX" | jq '.[].name'
Find large attachments (>1MB)
mail-app-cli attachments list <message-id> -a "Gmail" -m "INBOX" | jq '.[] | select(.fileSize > 1048576)'
Scripting Examples
Check for unread messages
#!/bin/bash
unread=$(mail-app-cli messages list -a "Gmail" -m "INBOX" --unread | jq 'length')
if [ $unread -gt 0 ]; then
  echo "You have $unread unread messages"
fi
Archive all read messages
#!/bin/bash
mail-app-cli messages list -a "Gmail" -m "INBOX" | jq -r '.[] | select(.read==true) | .id' | while read -r msg_id; do
  mail-app-cli messages archive "$msg_id" -a "Gmail" -m "INBOX"
done
Daily unread summary
#!/bin/bash
echo "Today's Unread Email Summary"
echo "============================"
mail-app-cli mailboxes list | jq -r '.[] | select(.unreadCount > 0) | "\(.account)/\(.name): \(.unreadCount) unread"'
Save all attachments from a sender
#!/bin/bash
SENDER="colleague@company.com"
ACCOUNT="Gmail"
MAILBOX="INBOX"

# Find all messages from sender
mail-app-cli messages list -a "$ACCOUNT" -m "$MAILBOX" | jq -r ".[] | select(.sender | contains(\"$SENDER\")) | .id" | while read -r msg_id; do
  # Get attachments for each message
  mail-app-cli attachments list "$msg_id" -a "$ACCOUNT" -m "$MAILBOX" | jq -r '.[].name' | while read -r att_name; do
    echo "Saving: $att_name from message $msg_id"
    mail-app-cli attachments save "$msg_id" "$att_name" -a "$ACCOUNT" -m "$MAILBOX" -o "~/Downloads/$att_name"
  done
done

Project Structure

mail-app-cli/
├── cmd/              # Cobra command definitions
│   ├── root.go
│   ├── accounts.go
│   ├── batch.go
│   ├── doctor.go
│   ├── drafts.go
│   ├── export.go
│   ├── import.go
│   ├── mailboxes.go
│   ├── messages.go
│   ├── recent.go
│   ├── rules.go
│   ├── send.go
│   ├── search.go
│   ├── signatures.go
│   ├── smart.go
│   ├── threads.go
│   ├── vip.go
│   └── attachments.go
├── pkg/
│   └── mail/        # Mail.app AppleScript/JXA client
│       ├── accounts.go
│       ├── attachments.go
│       ├── automation.go
│       ├── bulk.go
│       ├── client.go
│       ├── drafts.go
│       ├── envelope_index.go
│       ├── mailboxes.go
│       ├── message_actions.go
│       ├── message_content.go
│       ├── messages.go
│       ├── models.go
│       ├── recent.go
│       ├── rules.go
│       ├── search.go
│       ├── send.go
│       ├── signatures.go
│       ├── smart_mailboxes.go
│       ├── sync.go
│       └── unified.go
└── main.go

How It Works

The CLI uses AppleScript and JavaScript for Automation (JXA) to interact with Mail.app. This provides:

  • Native integration with Mail.app
  • Access to all Mail.app features
  • No external dependencies or APIs required
  • Works with all mail providers configured in Mail.app

Requirements

  • macOS (tested on macOS 15+)
  • Mail.app configured with at least one account
  • Go 1.21+ (for building from source)

Development

Prerequisites
  • Go 1.21 or higher
  • macOS with Mail.app
Building
go build -o mail-app-cli
Testing
# Test account listing
./mail-app-cli accounts list

# Test mailbox listing
./mail-app-cli mailboxes list

# Test message listing
./mail-app-cli messages list -a "Your Account" -m "INBOX" --limit 5

This project is a hard fork of intelligrit/mail-app-cli.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL