Apple Mail

Jehadur Rahman (Emran)@jehadurre

Apple Mail channel plugin for OpenClaw and Hermes - uses AppleScript to send/receive emails via Mail.app on macOS with per-thread session isolation

Readme

๐Ÿ“ง openclaw-apple-mail

npm version npm downloads License: MIT OpenClaw macOS

Apple Mail channel plugin for OpenClaw and Hermes. Uses AppleScript to integrate with Mail.app on macOS, providing isolated sessions per email thread.

โœจ Key Features

๐Ÿ”’ Per-Thread Session Isolation

Each email thread gets its own OpenClaw/Hermes session via the session key:

text
agent:main:apple-mail:{email}:{threadId}

This ensures:

  • โœ… Each email thread has isolated conversation history
  • โœ… No mixing of conversations between different emails
  • โœ… Follow-ups automatically go to the correct thread
  • โœ… Works with OpenClaw's built-in session management

๐Ÿ›ก๏ธ Security Features

  • Allowlist enforcement: Only process emails from approved senders
  • Self-reply prevention: Avoids infinite loops
  • Outbound restrictions: Control who can receive replies
  • Thread reply policies: Flexible access control

๐Ÿ“Š HTML Table Support

  • Extract and process HTML tables from emails
  • Preserve table structure and formatting
  • Sanitize HTML content for security

๐Ÿš€ Quick Start

Prerequisites

  • macOS with Mail.app configured
  • OpenClaw >= 2026.1.0 or Hermes >= 2026.1.0
  • Node.js >= 18.0.0

Installation

Via npm (Recommended):

bash
# Install from npm
npm install @jehadurre/openclaw-apple-mail

# For OpenClaw
openclaw plugins install @jehadurre/openclaw-apple-mail

# For Hermes
hermes plugins install @jehadurre/openclaw-apple-mail

Via Local Path:

bash
# Clone the repository
git clone https://github.com/JehadurRE/openclaw-apple-mail.git

# For OpenClaw
openclaw plugins install --link /path/to/openclaw-apple-mail

# For Hermes
hermes plugins install --link /path/to/openclaw-apple-mail
text

## โš™๏ธ Configuration

### For OpenClaw
Add to your `~/.openclaw/openclaw.json`:

```json
{
  "channels": {
    "apple-mail": {
      "enabled": true,
      "accounts": {
        "your-email@example.com": {
          "email": "your-email@example.com",
          "mailboxAccount": "iCloud",
          "allowFrom": [
            "allowed-sender@example.com",
            "another-sender@example.com"
          ],
          "pollIntervalMs": 30000,
          "archiveOnReply": false
        }
      }
    }
  }
}

For Hermes

Add to your ~/.hermes/hermes.json:

json
{
  "channels": {
    "apple-mail": {
      "enabled": true,
      "accounts": {
        "your-email@example.com": {
          "email": "your-email@example.com",
          "mailboxAccount": "iCloud",
          "allowFrom": [
            "allowed-sender@example.com"
          ],
          "pollIntervalMs": 30000
        }
      }
    }
  }
}

๐Ÿ“– Configuration Options

KeyTypeDefaultDescription
emailstringโ€”Email address (required)
mailboxAccountstring"iCloud"Apple Mail account name
allowFromstring[][]Sender allowlist. ["*"] allows all
pollIntervalMsnumber30000Polling interval in ms
archiveOnReplybooleanfalseArchive thread after reply
includeQuotedRepliesbooleantrueInclude thread history in replies
includeThreadContextbooleanfalseInclude context from non-allowed senders

๐Ÿ—๏ธ How It Works

text
Mail.app INBOX
    โ†“ (AppleScript polling)
AppleMailClient
    โ†“ (parse inbound)
OpenClaw/Hermes Gateway
    โ†“ (SessionKey: agent:main:apple-mail:email:threadId)
Agent (isolated session per thread)
    โ†“ (reply)
AppleMailClient.replyToMessage
    โ†“ (AppleScript)
Mail.app โ†’ Sent

Thread Detection

Generates stable thread IDs using:

typescript
threadId = md5(cleanSubject + ":" + senderEmail)

This ensures:

  • Same subject + sender = same thread
  • "Re:", "Fwd:" prefixes are normalized
  • Consistent thread tracking across conversations

๐Ÿ” Security Best Practices

  1. Use Allowlists: Always configure allowFrom in production
  2. Dedicated Accounts: Use separate email accounts for agent communication
  3. Monitor Logs: Regularly review session logs for suspicious activity
  4. Update Regularly: Keep the plugin updated for security patches
  5. File Permissions: Protect your configuration files (chmod 600)

๐Ÿ› ๏ธ Development

bash
# Clone the repository
git clone https://github.com/JehadurRE/openclaw-apple-mail.git
cd openclaw-apple-mail

# Install dependencies
npm install

# Build
npm run build

# Link for local testing with OpenClaw
openclaw plugins install --link .

# Or with Hermes
hermes plugins install --link .

๐Ÿ“ Architecture

  • src/channel.ts - Main channel implementation
  • src/applescript-client.ts - AppleScript interface
  • src/inbound.ts - Inbound message processing
  • src/outbound.ts - Outbound reply handling
  • src/monitor.ts - Email polling and monitoring
  • src/threading.ts - Thread ID generation
  • src/html-processor.ts - HTML table extraction
  • src/session-watcher.ts - Session state management

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

MIT License - see LICENSE file for details.

Copyright (c) 2026 Md. Jehadur Rahman (Emran)

๐Ÿ‘ค Author

Md. Jehadur Rahman (Emran)

๐Ÿ™ Acknowledgments

  • OpenClaw team for the extensible plugin architecture
  • Hermes team for AI agent framework
  • Apple Mail.app for AppleScript support

๐Ÿ“š Related Projects

๐Ÿ“ฎ Support


Made with โค๏ธ by Md. Jehadur Rahman (Emran)