Complete guide to using mailcli for email management.
- Configuration
- Listing Emails
- Searching Emails
- Viewing Emails
- Multiple Accounts
- Scripting Examples
- Advanced Tips
mailcli config addThe setup is now simplified to just 2 steps:
- Enter email address - Provider is auto-detected
- Enter password - Done! ✓
Example:
$ mailcli config add
Email address: user@gmail.com
✓ Detected provider: Gmail
Password (or app-specific password): ********
✓ Configuration saved!
📧 Account: Gmail (user@gmail.com)
🔗 Provider: GmailSupported providers (auto-detected from email):
- Gmail (@gmail.com)
- Outlook (@outlook.com)
- QQ Mail (@qq.com)
- 163/126 Mail (@163.com, @126.com)
- Yahoo Mail (@yahoo.com)
- iCloud (@icloud.com, @me.com)
For custom IMAP servers or detailed configuration options, see CONFIG_SIMPLIFICATION.md.
mailcli config listOutput:
Accounts:
* gmail (user@gmail.com) - default
work (user@company.com)
# Test default account
mailcli config test
# Test specific account
mailcli config test --account workmailcli config set-defaultSelect from the list of configured accounts.
mailcli config removeSelect the account to remove from the list.
# List recent emails (default: 20)
mailcli mail list
# List more emails
mailcli mail list --limit 50
# List with offset (pagination)
mailcli mail list --limit 20 --offset 20Output (text format):
[12345] john@example.com: Project Update (2024-03-19 10:30)
[12346] meeting@company.com: Weekly Sync (2024-03-19 09:00)
[12347] newsletter@news.io: Daily Digest (2024-03-19 08:15)
# List from Sent folder
mailcli mail list --folder "Sent"
# List from Archive
mailcli mail list --folder "Archive"
# List from custom folder
mailcli mail list --folder "Projects/Active"# Table format
mailcli mail list --output table
# JSON format
mailcli mail list --output jsonTable output:
┌───────────┬────────────────────┬──────────────────┬──────────────────────┐
│ UID │ FROM │ SUBJECT │ DATE │
├───────────┼────────────────────┼──────────────────┼──────────────────────┤
│ 12345 │ john@example.com │ Project Update │ 2024-03-19 10:30 │
│ 12346 │ meeting@company.com│ Weekly Sync │ 2024-03-19 09:00 │
└───────────┴────────────────────┴──────────────────┴──────────────────────┘
# Search unread emails
mailcli mail search --unread
# Search read emails
mailcli mail search --read
# Search flagged emails
mailcli mail search --flagged# Search from specific sender
mailcli mail search --from "john@example.com"
# Search to specific recipient
mailcli mail search --to "me@company.com"
# Partial match works too
mailcli mail search --from "john"# Search by subject
mailcli mail search --subject "project"
# Search by body content
mailcli mail search --body "meeting"
# Combine subject and body
mailcli mail search --subject "urgent" --body "deadline"# Search emails since a date
mailcli mail search --since 2024-01-01
# Search emails before a date
mailcli mail search --before 2024-12-31
# Date range
mailcli mail search --since 2024-01-01 --before 2024-03-31
# Recent emails (last 7 days)
mailcli mail search --since $(date -d '7 days ago' +%Y-%m-%d)# Unread emails
mailcli mail search --unread
# Read emails
mailcli mail search --read
# Flagged emails
mailcli mail search --flagged
# Answered emails
mailcli mail search --answered
# Draft emails
mailcli mail search --draft
# Deleted emails
mailcli mail search --deleted
# Recent emails
mailcli mail search --recent
# With attachments
mailcli mail search --has-attachment# Unread emails from boss
mailcli mail search --unread --from "boss@company.com"
# Flagged emails this week
mailcli mail search --flagged --since 2024-03-13
# Important emails from multiple senders
mailcli mail search --subject "urgent" --flagged --unread
# Large attachments
mailcli mail search --has-attachment --since 2024-01-01# Limit results
mailcli mail search --unread --limit 10
# Pagination
mailcli mail search --from "newsletter" --limit 20 --offset 20# View email by UID
mailcli mail get 12345Output:
From: john@example.com
To: user@gmail.com
Subject: Project Update
Date: 2024-03-19 10:30:45
Body:
Hi,
Just wanted to give you an update on the project...
Best,
John
# View email as JSON
mailcli mail get 12345 --format json
# Pretty print with jq
mailcli mail get 12345 --format json | jq# Use specific account
mailcli --account work mail get 54321# Initialize first account
mailcli config add
# Add second account (just run init again)
mailcli config add# Use specific account for one command
mailcli --account work mail list
mailcli --account personal mail search --unread
# Set default account
mailcli config set-default
# List all accounts
mailcli config list# Check unread emails across all accounts
for account in personal work; do
echo "=== $account ==="
mailcli --account "$account" mail search --unread --output json | jq -r '.[].subject'
done# Count unread
mailcli mail search --unread --output json | jq 'length'
# Count unread across accounts
for account in $(mailcli config list --output json | jq -r '.[].name'); do
count=$(mailcli --account "$account" mail search --unread --output json | jq 'length')
echo "$account: $count unread"
done# Get unique senders
mailcli mail list --limit 100 --output json | \
jq -r '.[].from' | sort | uniq -c | sort -rn# Find emails with attachments (potential large files)
mailcli mail search --has-attachment --output json | \
jq 'select(.size > 1000000)'# Export email headers to CSV
mailcli mail list --output json | \
jq -r '.[] | [.uid, .from, .subject, .date] | @csv' > emails.csv# Watch for new emails (check every 60 seconds)
while true; do
count=$(mailcli mail search --unread --output json | jq 'length')
echo "$(date): $count unread emails"
sleep 60
done# Mark all newsletter emails as read (conceptual - requires IMAP STORE)
mailcli mail search --from "newsletter@" --output json | \
jq -r '.[].uid' | while read uid; do
# Would need IMAP STORE command to mark as read
echo "Would mark email $uid as read"
done# Add to crontab to check unread emails every hour
crontab -e
# Add line:
0 * * * * /usr/local/bin/mailcli mail search --unread --output json | jq 'length' > /tmp/unread_count.txtAdd to ~/.bashrc or ~/.zshrc:
# Quick aliases
alias unread='mailcli mail search --unread'
alias inbox='mailcli mail list --limit 20'
alias sent='mailcli mail list --folder "Sent"'
alias workmail='mailcli --account work mail list'
alias personalmail='mailcli --account personal mail list'# Interactive email search
mailcli mail list --output json | \
jq -r '.[] | "\(.uid) \(.from) \(.subject)"' | \
fzf | \
awk '{print $1}' | \
xargs mailcli mail get# View long email lists
mailcli mail list --limit 100 | less
# View email body with pagination
mailcli mail get 12345 | less# Colorize JSON output
mailcli mail list --output json | jq -C
# Colorize with grc (generic colouriser)
mailcli mail list | grc cat# Faster: use specific folder
mailcli mail search --folder "INBOX" --unread
# Slower: search all folders
mailcli mail search --unread# Fetch in batches
mailcli mail list --limit 100 --offset 0
mailcli mail list --limit 100 --offset 100
mailcli mail list --limit 100 --offset 200# Save to file for reuse
mailcli mail search --unread --output json > /tmp/unread.json
# Use cached file
jq '.[].subject' /tmp/unread.jsonProblem: Search is slow with many emails.
Solution:
- Use more specific filters (date range, sender)
- Limit folder scope
- Use pagination
Problem: "connection refused" or "timeout".
Solution:
- Test connection:
mailcli config test - Check network connectivity
- Verify firewall settings
- Check IMAP server status
Problem: "authentication failed".
Solution:
- Use app-specific password for Gmail
- Enable IMAP in account settings
- Verify username and password
- Check for account locks
Problem: Search returns no results.
Solution:
- Check if folder exists:
mailcli mail list --folder "All Mail" - Verify search criteria
- Try broader search first
- Check account permissions
- Use app-specific passwords for Gmail/Yahoo
- Enable IMAP in email provider settings
- Use JSON output for scripting
- Set default account if using multiple accounts
- Use specific folders to improve performance
- Limit results for large mailboxes
- Test connection after configuration changes
- Keep binary updated for bug fixes and features
- README.md - Project overview
- INSTALL.md - Installation guide
- FAQ.md - Common questions
- CONFIG_SIMPLIFICATION.md - Detailed configuration guide
- TIME_HANDLING.md - Timezone handling details
- GitHub Issues - Report bugs