Skip to content

Save Command

Save emails to file in multiple formats including EML, plain text, and JSON.

Overview

The save command allows you to export emails from your mailbox to local files. EML format is the default and preserves the complete email structure, making it viewable in any email client. Text and JSON formats are also available for different use cases.

Usage

bash
# Single email mode
mailos save <email-id> [flags]

# Thread download mode
mailos save --thread-for <email-address> [flags]

# Batch mode (search criteria)
mailos save --from <sender> [flags]
mailos save --subject <pattern> [flags]

Basic Examples

Save email as EML (default)

bash
# Save email to current directory
mailos save 1234 --account [email protected]

# Save to specific directory
mailos save 1234 --account [email protected] --output-dir ~/emails

# Save and open in mail client
mailos save 1234 --account [email protected] --open

Save in different formats

bash
# Save as plain text
mailos save 1234 --account [email protected] --format txt

# Save as JSON
mailos save 1234 --account [email protected] --format json

# Save without headers
mailos save 1234 --account [email protected] --include-headers=false

Advanced Usage

Custom filename and organization

bash
# Custom file prefix
mailos save 1234 --account [email protected] --file-prefix "archived_"

# Organized by date in specific directory
mailos save 1234 --account [email protected] \
  --output-dir ~/email-archive/$(date +%Y-%m) \
  --file-prefix "work_"

Batch saving workflow

bash
# Find emails and save them
mailos search --account [email protected] --from [email protected] --days 7 --json | \
jq -r '.[].id' | \
while read email_id; do
  mailos save "$email_id" --account [email protected] --output-dir ~/important-emails
done

Thread Download Functionality

The save command supports downloading complete email threads involving specific email addresses or aliases. This is useful for archiving conversations, backing up important communications, or analyzing email patterns.

Save emails for specific alias or address

bash
# Download all emails FROM and TO a specific alias
mailos save --account [email protected] --thread-for [email protected] --format eml --output-dir ./thread-backup

# Download all threads for the current account
mailos save --account [email protected] --all-threads --output-dir ./all-threads --days 90

# Download threads with specific date range and format
mailos save --account [email protected] --thread-for [email protected] --days 365 --format json --output-dir ./client-archive

Thread download features

  • Alias Support: Works with email aliases and cross-domain addresses
  • Deduplication: Automatically removes duplicate emails based on Message-ID
  • Thread Summary: Generates markdown summary with participant analysis and email timeline
  • Filtering: Only includes emails that actually contain the specified address in TO/FROM/CC/BCC fields
  • Multiple Formats: Supports EML, TXT, and JSON output formats

Thread summary generation

When using thread download, a thread_summary.md file is automatically created containing:

  • Total email count and participant statistics
  • Email timeline with previews
  • Attachment information
  • Thread conversation analysis

Thread download examples

bash
# Archive all communications with a specific client
mailos save --account [email protected] --thread-for [email protected] --output-dir ./client-archive --days 365

# Backup alias-based communications
mailos save --account [PERSONAL_ACCOUNT] --thread-for [ALIAS_ADDRESS] --format eml --output-dir ./alias-backup

# Download recent threads for compliance
mailos save --account [LEGAL_ACCOUNT] --all-threads --days 30 --format json --output-dir ./compliance-archive

Batch Operations

Save multiple emails by criteria

bash
# Save emails from specific sender (last 30 days)
mailos save --account [email protected] --from [VENDOR_ADDRESS] --format eml --output-dir ./vendor-emails

# Save emails by subject pattern
mailos save --account [email protected] --subject "invoice" --days 30 --format json --output-dir ./invoices

# Save only attachments from specific sender
mailos save --account [email protected] --from [email protected] --attachments-only --output-dir ./client-attachments

Output Formats

EML Format (default)

  • Use case: Viewing in email clients, archiving, forwarding
  • Features: Preserves all email structure, headers, attachments
  • Extension: .eml
  • Compatibility: Works with Mail.app, Outlook, Thunderbird, etc.

Text Format

  • Use case: Reading content, text processing, simple archiving
  • Features: Headers + plain text body only
  • Extension: .txt
  • Content: From, To, Subject, Date, and body text

JSON Format

  • Use case: Data processing, integration with other tools
  • Features: Complete structured email data
  • Extension: .json
  • Content: All email fields as JSON object

Filename Convention

Saved files use this naming pattern:

[prefix][timestamp]_[subject].ext

Examples:

  • email_20241201_143022_Meeting_Notes.eml
  • archived_20241201_143022_Invoice_12345.txt
  • backup_20241201_143022_Project_Update.json

Integration Examples

Save emails from search results

bash
# Save all emails from specific sender
mailos search --account [email protected] --from [VENDOR_ADDRESS] --json | \
jq -r '.[].id' | head -10 | \
xargs -I {} mailos save {} --account [email protected] --output-dir ~/vendor-emails

# Save important emails by subject
mailos search --account [email protected] --subject "invoice" --days 30 --json | \
jq -r '.[].id' | \
xargs -I {} mailos save {} --account [email protected] --format json --output-dir ~/invoices

Archive workflow

bash
#!/bin/bash
# Archive old emails script
ACCOUNT="[email protected]"
ARCHIVE_DIR="$HOME/email-archive/$(date +%Y)"

# Create archive directory
mkdir -p "$ARCHIVE_DIR"

# Find emails older than 6 months and archive them
mailos search --account "$ACCOUNT" --older-than-days 180 --limit 100 --json | \
jq -r '.[].id' | \
while read email_id; do
  echo "Archiving email $email_id..."
  mailos save "$email_id" --account "$ACCOUNT" \
    --output-dir "$ARCHIVE_DIR" \
    --file-prefix "archived_" \
    --format eml
done

Error Handling

Common issues and solutions:

Email not found

bash
mailos save 99999 --account [email protected]
# Error: email with ID 99999 not found

Solution: Verify email ID with mailos search first.

Permission denied

bash
mailos save 1234 --account [email protected] --output-dir /root/emails
# Error: failed to create output directory: permission denied

Solution: Use a writable directory or run with appropriate permissions.

Disk space

bash
# Check available space before saving
df -h ~/email-archive
mailos save 1234 --account [email protected] --output-dir ~/email-archive

Security Considerations

File permissions

Saved emails contain sensitive information:

bash
# Save with restricted permissions
umask 077  # Only owner can read
mailos save 1234 --account [email protected] --output-dir ~/private-emails

Cleanup

bash
# Clean up temporary files after viewing
mailos save 1234 --account [email protected] --open --cleanup-temp

Tips and Best Practices

  1. Use EML for long-term archiving - Most compatible format
  2. Organize by date - Use --output-dir with date-based paths
  3. Verify before bulk operations - Test save commands with single emails first
  4. Check disk space - Email archives can grow large quickly
  5. Use descriptive prefixes - Help organize different types of saved emails

Command Reference

Save an email to a file in EML, text, or JSON format. EML format is the default and preserves full email structure for viewing in email clients.

Usage

bash
# Single email mode
mailos save <email-id> [flags]

# Thread download mode  
mailos save --thread-for <email-address> [flags]

# Batch mode (search criteria)
mailos save --from <sender> [flags] 
mailos save --subject <pattern> [flags]

Flags

Basic Save Options

FlagShortTypeDefaultDescription
--account-astringEmail account to use
--cleanup-tempbooltrueClean up temporary files after opening
--dry-runboolfalsePreview what would be done without actually doing it
--file-prefixstring"email_"Prefix for saved email filename
--formatstring"eml"Output format: eml, txt, json (default: eml)
--include-headersbooltrueInclude email headers in output
--openboolfalseOpen saved email in default mail client
--output-dirstringOutput directory for saved email (default: current directory)

Thread and Batch Operations

FlagShortTypeDefaultDescription
--all-threadsboolfalseDownload all email threads for the specified account
--attachments-onlyboolfalseSave only attachments, not email content
--daysint0Search emails from last N days (0 = no limit, max: 365)
--fromstringFilter emails by sender address
--limitint10Maximum number of emails to search (default: 10, max: 1000)
--show-contentboolfalseShow email content preview with details
--subjectstringFilter emails by subject line (partial match)
--thread-forstringDownload all email threads involving this email address
--tostringFilter emails by recipient address

Arguments

  • <email-id> - The unique ID of the email to save

Examples

Single Email Save

bash
# Save email as EML to current directory
mailos save 1234 --account [email protected]

# Save as JSON to specific directory
mailos save 1234 --account [email protected] --format json --output-dir ~/exports

# Save and open in mail client
mailos save 1234 --account [email protected] --open

# Save with custom prefix and no headers
mailos save 1234 --account [email protected] --file-prefix "backup_" --include-headers=false

Thread Download Examples

bash
# Download all emails for a specific alias
mailos save --account [WORK_ACCOUNT] --thread-for [ALIAS_ADDRESS] --output-dir ~/alias-archive

# Download all account threads from last 30 days
mailos save --account [email protected] --all-threads --days 30 --format eml --output-dir ~/monthly-backup

# Download specific sender's thread as JSON
mailos save --account [email protected] --thread-for [email protected] --format json --output-dir ~/client-comms

Batch Operations

bash
# Save all emails from specific sender (last 7 days)
mailos save --account [email protected] --from [VENDOR_ADDRESS] --days 7 --output-dir ~/vendor

# Save only attachments from client emails
mailos save --account [email protected] --from [email protected] --attachments-only --output-dir ~/attachments

Released under the MIT License.