#
Building an Apple Mail Channel Plugin for OpenClaw
I recently built and published a plugin that integrates Apple Mail with OpenClaw (an AI automation platform), allowing AI agents to monitor and respond to emails with per-thread session isolation.
#
π― The Problem
OpenClaw and Hermes are powerful AI automation platforms, but they lacked native Apple Mail integration on macOS. Users wanted to:
- Monitor multiple email accounts
- Have AI agents automatically respond to emails
- Maintain conversation context across email threads
- Keep different email conversations isolated
#
π‘ The Solution
I built @jehadurre/openclaw-apple-mail
- a channel plugin that:
- Connects to Apple Mail via AppleScript
- Creates isolated sessions per email thread
- Processes HTML emails intelligently
- Supports multi-account configuration
- Includes security features like sender allowlists
#
π οΈ Technical Stack
TypeScript - Type-safe development #
AppleScript - Native macOS Mail.app integration #
HTML Processing - DOMPurify, jsdom, sanitize-html, marked #
Schema Validation - Zod for configuration validation
#
π¦ Key Features
- Per-Thread Session Isolation
Each email conversation gets its own isolated session, preventing context mixing:
- Multi-Account Support
Configure multiple email accounts with independent settings:
- Security Features
- Sender allowlist per account
- HTML sanitization
- AppleScript sandboxing
- Smart HTML Processing
Automatically converts HTML emails to clean markdown:
- Table extraction and conversion
- Removes tracking pixels
- Sanitizes malicious content
- Preserves formatting for AI agents
#
π Publishing Journey
I published this plugin to multiple platforms:
- npm Registry
- GitHub
- Full source code
- Issue tracking
- Contribution guidelines
- MIT License
- ClawHub
- OpenClaw Skill
Created a comprehensive setup skill:
The skill includes:
- Installation guide
- 5 configuration templates
- Troubleshooting solutions
- Best practices
#
π Lessons Learned
- Compiled Output Matters
ClawHub requires compiled JavaScript, not just TypeScript source. I had to:
- Get compiled output from production deployment
- Include
index.js
in the package
- Update
package.json
to reference the compiled file
- Skills Enhance Adoption
Creating a separate "skill" package that teaches users how to set up and use the plugin significantly improves the user experience.
- Multi-Platform Publishing
Publishing to npm, GitHub, ClawHub, and creating documentation on GitHub Pages maximizes discoverability.
#
π Usage Example
Here's how users set it up:
Step 1: Install
Step 2: Configure
Add to openclaw.json
:
Step 3: Start
That's it! OpenClaw now monitors your email and can respond automatically.
#
π Architecture
#
π Security Considerations
Sender Allowlist: Only process emails from trusted senders #
HTML Sanitization: Remove malicious content from HTML emails #
AppleScript Sandboxing: Limited access to Mail.app APIs #
No Credential Storage: Uses existing Apple Mail accounts
#
π Future Enhancements
Planned features:
- [ ] Smart reply suggestions
- [ ] Attachment handling
- [ ] Email categorization
- [ ] Custom email templates
- [ ] Integration with other channels
#
π Resources
#
π€ Contributing
Contributions welcome! Check out the Contributing Guide.
#
π¬ Feedback
Have you used AI automation with email? What features would you like to see? Let me know in the comments!
About Me: I'm Md. Jehadur Rahman (Emran), a developer passionate about AI automation and productivity tools. Find me on GitHub and my website.
License: MIT - Free to use, modify, and redistribute!