e-mail-agent-skill is a Microsoft-first, provider-ready email automation toolkit for agents.
It ships as a real CLI plus a Codex-style skill payload, so an agent can install it, authenticate once, and operate a mailbox through terminal commands instead of a GUI.
The first implementation target is Microsoft 365 via Microsoft Graph. The internal architecture is intentionally provider-neutral so Gmail and Amazon WorkMail can be added later without redesigning the CLI surface.
- Microsoft 365 / Exchange Online via Microsoft Graph
- Device-code OAuth for local terminal use
- Persisted Microsoft session cache with automatic reuse and refresh
- Search messages server-side
- Read full messages
- Create and update drafts
- Send drafts and direct messages
- Move and archive messages
- Mark messages as read
- Auth status, export, and clear helpers
- Low-level Graph request escape hatch
- Installer that copies the skill payload into
~/.codex/skills
npm install -g @codecell-germany/e-mail-agent-skille-mail-agent-cli --help
e-mail-agent-skill --helpe-mail-agent-skill install --forceRequirements:
- Node.js
>= 20 - Microsoft Entra app registration with a client ID
- Shell environment variables for the Microsoft provider
If this is the first Microsoft 365 setup, print the built-in setup guide first:
e-mail-agent-cli setup m365 --language enGerman output is also available:
e-mail-agent-cli setup m365 --language deDetailed click-by-click reference:
skills/e-mail-agent-cli/references/agent-onboarding.mdskills/e-mail-agent-cli/references/overview.mdskills/e-mail-agent-cli/references/m365-first-run.md
If you also need shared or delegated mailboxes, add these delegated Microsoft Graph permissions in the app registration:
Mail.ReadWrite.SharedMail.Send.Shared
The permission model for shared mailboxes is therefore documented, but the signed-in Microsoft 365 user must still have the matching Exchange mailbox rights.
Required environment variables:
export EMAIL_AGENT_PROVIDER="m365"
export EMAIL_AGENT_M365_CLIENT_ID="..."
export EMAIL_AGENT_M365_TENANT="organizations"By default, the CLI requests both own-mailbox and shared-mailbox Microsoft Graph scopes so shared mailboxes work without a second redesign. If a tenant wants a narrower token request, it can override the scope manually:
export EMAIL_AGENT_M365_SCOPE="openid profile offline_access User.Read Mail.ReadWrite Mail.Send"Start the browser login once and persist the session locally:
e-mail-agent-cli auth login m365 --persistIf permissions were added later in the Entra app registration, rerun the login with --force so Microsoft can issue a fresh token with the updated consent:
e-mail-agent-cli auth login m365 --persist --forceThen validate access:
e-mail-agent-cli doctor --provider m365 --json
e-mail-agent-cli folders list --provider m365 --json
e-mail-agent-cli doctor --provider m365 --mailbox admin@codecell.de --jsonNormal mailbox commands automatically reuse the persisted session. No new device-code flow should be needed for every command.
Only if you explicitly need shell exports for another process, export them from the existing persisted session:
e-mail-agent-cli auth export m365 --write-env-file ~/.config/e-mail-agent-cli/m365.env
source ~/.config/e-mail-agent-cli/m365.envIf a fresh agent is using this skill, the correct first-run order is:
e-mail-agent-cli --helpe-mail-agent-cli doctor --provider m365 --json- if setup is incomplete, print
e-mail-agent-cli setup m365 --language en|de - collect only:
EMAIL_AGENT_M365_CLIENT_IDEMAIL_AGENT_M365_TENANT
- never ask for:
- client secret
- access token
- refresh token
- run browser OAuth:
e-mail-agent-cli auth login m365 --persist
- present the Microsoft login URL and code to the user
- rerun
doctor - only then start mailbox operations
For an already configured machine, the agent should prefer:
e-mail-agent-cli auth status m365 --json
e-mail-agent-cli doctor --provider m365 --jsonIf a valid persisted session exists, the agent should continue directly to mailbox commands instead of triggering a fresh login.
e-mail-agent-cli mail search \
--provider m365 \
--query "invoice" \
--limit 25 \
--body-format text \
--jsone-mail-agent-cli mail show \
--provider m365 \
--id "<message-id>" \
--body-format text \
--jsone-mail-agent-cli mail search \
--provider m365 \
--mailbox admin@codecell.de \
--query "invoice" \
--limit 10 \
--body-format text \
--jsone-mail-agent-cli draft create \
--provider m365 \
--to person@example.com \
--subject "Follow-up" \
--body-file /absolute/path/to/body.txt \
--body-content-type text \
--jsone-mail-agent-cli draft send \
--provider m365 \
--id "<draft-id>" \
--execute \
--confirm-send yese-mail-agent-cli mail send \
--provider m365 \
--to person@example.com \
--subject "Hello" \
--body "Hello from the CLI." \
--execute \
--confirm-send yese-mail-agent-cli mail send \
--provider m365 \
--mailbox admin@codecell.de \
--to person@example.com \
--subject "Hello" \
--body "Hello from the shared mailbox." \
--execute \
--confirm-send yese-mail-agent-cli mail archive \
--provider m365 \
--id "<message-id>" \
--execute \
--jsonThis project is static-env-first and session-cache-first.
Static configuration still comes from environment variables:
EMAIL_AGENT_PROVIDEREMAIL_AGENT_M365_CLIENT_IDEMAIL_AGENT_M365_TENANT- optional:
EMAIL_AGENT_M365_SCOPE - optional:
EMAIL_AGENT_M365_API_BASE_URL
After auth login, the CLI persists the Microsoft session locally and later commands reuse it automatically.
On macOS, the default backend is the Keychain. A file backend can be forced for debugging or non-macOS environments.
Useful auth commands:
e-mail-agent-cli auth login m365 --persist
e-mail-agent-cli auth status m365 --json
e-mail-agent-cli auth refresh m365 --json
e-mail-agent-cli auth export m365 --write-env-file ~/.config/e-mail-agent-cli/m365.env
e-mail-agent-cli auth clear m365 --jsonExported shell files include both static Microsoft settings and the current session values:
EMAIL_AGENT_M365_CLIENT_IDEMAIL_AGENT_M365_TENANTEMAIL_AGENT_M365_SCOPEEMAIL_AGENT_M365_API_BASE_URLEMAIL_AGENT_M365_ACCESS_TOKENEMAIL_AGENT_M365_REFRESH_TOKENEMAIL_AGENT_M365_EXPIRES_AT
Built-in setup guide:
e-mail-agent-cli setup m365 --language ene-mail-agent-cli setup m365 --language de
- The default auth path does not print tokens to STDOUT. Sensitive exports are only emitted when
--shell bashor--write-env-fileis used explicitly. - Persisted sessions are local-only. On macOS, the default storage backend is the Keychain.
- Do not paste token values into prompts, tickets, screenshots, or logs.
- Shared mailbox access requires both Graph delegated permissions and real Exchange mailbox rights for the signed-in user.
- The high-level CLI defaults to the signed-in user's mailbox. Shared mailbox access is an explicit opt-in via
--mailbox <address>. - If a tenant does not need shared mailboxes, it can narrow the requested OAuth scope through
EMAIL_AGENT_M365_SCOPE.
src/: CLI sourceskills/e-mail-agent-cli/SKILL.md: agent instructionsskills/e-mail-agent-cli/references/agent-onboarding.md: deterministic first-run workflow for agentsskills/e-mail-agent-cli/references/overview.md: main overview and workflow guideskills/e-mail-agent-cli/references/m365-first-run.md: first-run Microsoft 365 setupknowledge/: architecture, auth, release, and limitation notes
This repository is being rebuilt from a local Outlook cache prototype into a publishable skill-with-CLI project. The old local-file approach is no longer the primary product direction.
MIT
Please keep the original copyright and license notice when you use or adapt this project. If you build on top of it publicly, crediting Nikolas Gottschol / CodeCell is appreciated.
e-mail-agent-skill ist ein Microsoft-first, aber provider-neutral vorbereitetes E-Mail-Automations-Toolkit für Agenten.
Es besteht aus einem echten CLI plus einer Codex-Skill-Payload, damit ein Agent den Skill installieren, sich einmal authentifizieren und danach ein Postfach direkt über Terminal-Kommandos steuern kann.
Die erste echte Implementierung zielt auf Microsoft 365 über Microsoft Graph. Die interne Architektur wird bewusst so gebaut, dass Gmail und Amazon WorkMail später ohne Oberflächenbruch ergänzt werden können.
- Microsoft 365 / Exchange Online über Microsoft Graph
- Device-Code-OAuth für lokale Terminal-Nutzung
- serverseitige Suche über Nachrichten
- vollständiges Lesen einzelner Nachrichten
- Entwürfe anlegen und aktualisieren
- Entwürfe und Direktnachrichten senden
- Nachrichten verschieben und archivieren
- Nachrichten als gelesen markieren
- Low-Level-Graph-Request als Escape Hatch
- Installer, der die Skill-Payload nach
~/.codex/skillskopiert
npm install -g @codecell-germany/e-mail-agent-skille-mail-agent-cli --help
e-mail-agent-skill --helpe-mail-agent-skill install --forceVoraussetzungen:
- Node.js
>= 20 - Microsoft-Entra-App-Registrierung mit Client-ID
- Shell-Umgebungsvariablen für den Microsoft-Provider
Wenn dies der erste Microsoft-365-Setup ist, gib zuerst die eingebaute Anleitung aus:
e-mail-agent-cli setup m365 --language enDeutsche Ausgabe ist ebenfalls verfügbar:
e-mail-agent-cli setup m365 --language deDetaillierte Klick-für-Klick-Referenz:
skills/e-mail-agent-cli/references/m365-first-run.md
Wenn du zusätzlich auf freigegebene oder delegierte Postfächer zugreifen willst, füge in der App-Registrierung außerdem diese delegierten Microsoft-Graph-Berechtigungen hinzu:
Mail.ReadWrite.SharedMail.Send.Shared
Das Berechtigungsmodell für Shared Mailboxes ist damit dokumentiert, zusätzlich muss der angemeldete Microsoft-365-Benutzer aber die passenden Exchange-Rechte auf dieses Postfach haben.
Pflichtvariablen:
export EMAIL_AGENT_PROVIDER="m365"
export EMAIL_AGENT_M365_CLIENT_ID="..."
export EMAIL_AGENT_M365_TENANT="organizations"Standardmäßig fordert das CLI sowohl Berechtigungen für das eigene Postfach als auch für Shared Mailboxes an, damit freigegebene Postfächer ohne zweiten Umbau funktionieren. Wenn ein Mandant bewusst einen kleineren Token-Scope möchte, kann er ihn manuell überschreiben:
export EMAIL_AGENT_M365_SCOPE="openid profile offline_access User.Read Mail.ReadWrite Mail.Send"Login-Flow starten und die Exporte direkt in die aktuelle Bash-Session übernehmen:
eval "$(e-mail-agent-cli auth login m365 --shell bash)"Wenn später zusätzliche Berechtigungen in der App-Registrierung ergänzt wurden, sollte der Login einmal erneut ausgeführt werden, damit Microsoft einen frischen Token mit dem aktualisierten Consent ausstellt.
Danach Zugriff verifizieren:
e-mail-agent-cli doctor --provider m365 --json
e-mail-agent-cli folders list --provider m365 --json
e-mail-agent-cli doctor --provider m365 --mailbox admin@codecell.de --jsonSuche:
e-mail-agent-cli mail search \
--provider m365 \
--query "invoice" \
--limit 25 \
--body-format text \
--jsonNachricht lesen:
e-mail-agent-cli mail show \
--provider m365 \
--id "<message-id>" \
--body-format text \
--jsonAus einem Shared Postfach lesen:
e-mail-agent-cli mail search \
--provider m365 \
--mailbox admin@codecell.de \
--query "invoice" \
--limit 10 \
--body-format text \
--jsonEntwurf anlegen:
e-mail-agent-cli draft create \
--provider m365 \
--to person@example.com \
--subject "Follow-up" \
--body-file /absolute/path/to/body.txt \
--body-content-type text \
--jsonEntwurf senden:
e-mail-agent-cli draft send \
--provider m365 \
--id "<draft-id>" \
--execute \
--confirm-send yesNachricht archivieren:
e-mail-agent-cli mail archive \
--provider m365 \
--id "<message-id>" \
--execute \
--jsonAus einem Shared Postfach senden:
e-mail-agent-cli mail send \
--provider m365 \
--mailbox admin@codecell.de \
--to person@example.com \
--subject "Hallo" \
--body "Hallo aus dem Shared Postfach." \
--execute \
--confirm-send yesDieses Projekt ist bewusst Shell-Env-first gebaut. Tokens liegen nicht in einer versteckten internen Datenbank. Das CLI erzeugt Shell-Exports, die direkt evaluiert oder in eine Datei geschrieben und später gesourct werden können.
Typische Microsoft-Session-Variablen:
EMAIL_AGENT_M365_ACCESS_TOKENEMAIL_AGENT_M365_REFRESH_TOKENEMAIL_AGENT_M365_EXPIRES_AT
Eingebaute Setup-Anleitung:
e-mail-agent-cli setup m365 --language ene-mail-agent-cli setup m365 --language de
- Tokens liegen absichtlich in Shell-Umgebungsvariablen. Diese Werte sollten niemals in Prompts, Tickets, Screenshots oder Logs kopiert werden.
- Shared-Mailbox-Zugriff braucht immer zwei Ebenen: Graph-Delegated-Permissions und echte Exchange-Rechte für den angemeldeten Benutzer.
- Das High-Level-CLI arbeitet standardmäßig auf dem eigenen Postfach. Shared Mailboxes werden bewusst nur über
--mailbox <adresse>angesprochen. - Wenn ein Mandant keine Shared Mailboxes braucht, kann er den angeforderten OAuth-Scope über
EMAIL_AGENT_M365_SCOPEbewusst verkleinern.
src/: CLI-Quellcodeskills/e-mail-agent-cli/SKILL.md: Agenten-Instruktionenskills/e-mail-agent-cli/references/m365-first-run.md: Microsoft-365-First-Run-Setupknowledge/: Architektur-, Auth-, Release- und Limitations-Dokumente
Dieses Repository wird gerade von einem lokalen Outlook-Cache-Prototypen zu einem veröffentlichbaren Skill-mit-CLI-Projekt umgebaut. Der alte lokale Dateiansatz ist nicht mehr die primäre Produktlinie.
MIT
Bitte behalte beim Nutzen oder Weiterentwickeln dieses Projekts den ursprünglichen Copyright- und Lizenzhinweis bei. Wenn du öffentlich darauf aufbaust, ist eine Nennung von Nikolas Gottschol / CodeCell erwünscht.