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
# 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)
# 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] --openSave in different formats
# 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=falseAdvanced Usage
Custom filename and organization
# 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
# 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
doneThread 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
# 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-archiveThread 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
# 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-archiveBatch Operations
Save multiple emails by criteria
# 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-attachmentsOutput 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].extExamples:
email_20241201_143022_Meeting_Notes.emlarchived_20241201_143022_Invoice_12345.txtbackup_20241201_143022_Project_Update.json
Integration Examples
Save emails from search results
# 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 ~/invoicesArchive workflow
#!/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
doneError Handling
Common issues and solutions:
Email not found
mailos save 99999 --account [email protected]
# Error: email with ID 99999 not foundSolution: Verify email ID with mailos search first.
Permission denied
mailos save 1234 --account [email protected] --output-dir /root/emails
# Error: failed to create output directory: permission deniedSolution: Use a writable directory or run with appropriate permissions.
Disk space
# Check available space before saving
df -h ~/email-archive
mailos save 1234 --account [email protected] --output-dir ~/email-archiveSecurity Considerations
File permissions
Saved emails contain sensitive information:
# Save with restricted permissions
umask 077 # Only owner can read
mailos save 1234 --account [email protected] --output-dir ~/private-emailsCleanup
# Clean up temporary files after viewing
mailos save 1234 --account [email protected] --open --cleanup-tempRelated Commands
mailos read- Read emails in the terminalmailos search- Find emails to savemailos download- Download email attachments
Tips and Best Practices
- Use EML for long-term archiving - Most compatible format
- Organize by date - Use
--output-dirwith date-based paths - Verify before bulk operations - Test save commands with single emails first
- Check disk space - Email archives can grow large quickly
- 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
# 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
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--account | -a | string | Email account to use | |
--cleanup-temp | bool | true | Clean up temporary files after opening | |
--dry-run | bool | false | Preview what would be done without actually doing it | |
--file-prefix | string | "email_" | Prefix for saved email filename | |
--format | string | "eml" | Output format: eml, txt, json (default: eml) | |
--include-headers | bool | true | Include email headers in output | |
--open | bool | false | Open saved email in default mail client | |
--output-dir | string | Output directory for saved email (default: current directory) |
Thread and Batch Operations
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--all-threads | bool | false | Download all email threads for the specified account | |
--attachments-only | bool | false | Save only attachments, not email content | |
--days | int | 0 | Search emails from last N days (0 = no limit, max: 365) | |
--from | string | Filter emails by sender address | ||
--limit | int | 10 | Maximum number of emails to search (default: 10, max: 1000) | |
--show-content | bool | false | Show email content preview with details | |
--subject | string | Filter emails by subject line (partial match) | ||
--thread-for | string | Download all email threads involving this email address | ||
--to | string | Filter emails by recipient address |
Arguments
<email-id>- The unique ID of the email to save
Examples
Single Email Save
# 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=falseThread Download Examples
# 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-commsBatch Operations
# 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