pip install mailcode

Control AI Agents
Via Email

Turn your email inbox into a remote control for AI coding agents. MailCode bridges OpenCode and Claude Code — send tasks, receive results, and inject commands, all through any email account. Zero third-party dependencies.

Why MailCode

Built for developers who need to stay in control of their AI agents, from anywhere.

Scheduled Tasks

Cron-based email scheduling for recurring automation — nightly backups, daily reports, automated code reviews.

0 9 * * * Run daily code review
💬

Terminal Chat

Start an interactive REPL with the AI directly from your terminal — no email needed. Resume any existing session created by the relay, or start a fresh conversation.

mailcode chat --session-id <id>
📁

Session Persistence

Conversations stored as individual files on disk. Resume across serve and chat modes, or pick up where you left off after a restart. Sessions auto-expire based on configurable TTL.

mailcode session list
🛡️

Multi-Layer Security

DKIM/SPF authentication, sender whitelist, command blacklist, and auto-expiring sessions. Every incoming email is verified before execution.

Enterprise-grade protection

Dual Mode

Session mode for persistent multi-turn conversations + stateless mode for one-shot commands. Sticky working directory in session mode.

Session · Stateless
🌐

Any Email Provider

Gmail, Outlook, QQMail, 126Mail — IMAP IDLE long connection for instant command delivery.

Gmail · Outlook · QQMail · 126Mail

How It Works

MailCode creates a simple bridge between your email inbox and AI coding agents.

✉️

Send an Email

A coding task or command, sent from any email client — phone, tablet, or laptop.

📡

IMAP Listener

MailCode polls your inbox in real time via IMAP IDLE, detecting new messages instantly.

AI Processing

Commands are forwarded to a claude -p subprocess. The AI works on your task and streams the response back.

📬

Get Notified

Task completes? You receive an email with the AI's response. Reply to continue the conversation.

Two Ways to Use It

Choose between multi-turn conversations or one-shot commands — whatever fits your workflow.

Session Mode

Multi-Turn Conversations

MailCode groups emails by subject into persistent sessions. Reply to the same email thread and the AI remembers context — no need to repeat yourself. The working directory (cwd) is sticky: set it once in your first email and all follow-ups reuse it. Sessions survive restarts and can be resumed via mailcode chat --session-id <id>.

Your first email: cwd: ~/Projects/my-app Add error handling to the login module Reply to continue — AI remembers context: Now add unit tests for those error cases
Stateless Mode

One-Shot Commands

Set session.enabled = false in your config for simple single-reply mode. Each email is processed independently — no conversation history is carried over. The cwd directive is parsed fresh every time. Perfect for scheduled tasks or quick one-off queries.

Your email — no context carried over: cwd: ~/Projects/my-app Run the test suite and report failures

Works With Any Email Provider

Configure SMTP and IMAP for your preferred email service.

Real Scenarios

Developers use MailCode to stay connected to their codebase no matter where they are.

🚀

Mobile Development

Send emails from your phone to trigger AI coding tasks while commuting or away from your desk. Review results and iterate — all from your pocket.

🔄

Scheduled Automation

Configure cron-like email triggers for nightly backups, dependency updates, or automated refactoring — without keeping a laptop open.

🔗

Remote Collaboration

Production issue while traveling? Send an email with the hotfix command. MailCode cold-starts your agent, applies the patch, and confirms the result.

Open Source

MailCode is fully open source under the MIT License — free for everyone, for any purpose.
Contributions, issues, and stars are welcome on GitHub.

Install in One Command

Requires Python 3.9+ and an AI agent CLI (Claude Code or OpenCode).

pip install mailcode
mailcode config init
mailcode serve

Run mailcode config init to configure your email credentials, then start the relay with mailcode serve.

Ready to Control Your AI Agent From Anywhere?

Install MailCode in one command and bridge your email to AI in minutes. Completely free and open source.

Open Source · MIT License · Python 3.9+