e-mail-agent-cli
e-mail-agent-cli
When to use
Use this skill when tasks require mailbox access from a local terminal workflow and the preferred interface is a CLI instead of a GUI.
Use it especially when an agent must:
- authenticate against Microsoft 365 from the terminal,
- search messages server-side,
- read message bodies,
- create and update drafts,
- send messages safely,
- archive or move messages without deleting them.
Preconditions
- Treat
e-mail-agent-clias the product surface. - First check whether it is available on
PATH:- verify:
e-mail-agent-cli --help - if missing, treat that as "not installed yet"
- preferred install path:
npm install -g @codecell-germany/e-mail-agent-skill - install the skill payload only after the CLI itself exists:
e-mail-agent-skill install --force
- verify:
- Do not bypass the public CLI by probing repo-local
dist/, hidden Codex tool folders, or old local shims. - Do not use Outlook cache files or local profile parsing as a fallback for this skill.
First-run detection
Run this check before any mailbox workflow:
e-mail-agent-cli auth status m365 --json
e-mail-agent-cli doctor --provider m365 --json
Treat the environment as "not fully set up" if any of these are true:
- the CLI is missing
doctorcannot runenv.clientIdPresentisfalseandsessionCache.clientIdPresentisfalseauthenticatedisfalsesessionCache.availableisfalseand no valid env token existssessionCache.autoRefreshReadyisfalsewhen the current access token is expired- the user says this is the first Microsoft 365 setup
- the user wants shared mailbox access that has not been verified yet
If setup is incomplete, switch into onboarding mode immediately.
Do not attempt folders list, mail search, mail show, or raw Graph requests first.
Onboarding mode
This is the exact first-run order for a new or partially configured user:
- Tell the user setup is not complete yet.
- Print the built-in setup guide in the user's preferred language:
- English:
e-mail-agent-cli setup m365 --language en - German:
e-mail-agent-cli setup m365 --language de
- English:
- Ask only for the static Microsoft values that may still be missing:
EMAIL_AGENT_M365_CLIENT_IDEMAIL_AGENT_M365_TENANT
- Never ask for:
- a client secret
- an access token
- a refresh token
- Once the user provides client ID and tenant ID, set or echo the static exports:
EMAIL_AGENT_PROVIDER=m365EMAIL_AGENT_M365_CLIENT_ID=<client-id>EMAIL_AGENT_M365_TENANT=<tenant-id-or-organizations>
- Start browser OAuth:
e-mail-agent-cli auth login m365 --persist
- The login command prints a Microsoft device-code prompt. The agent must relay the verification URL and the device code to the user explicitly and wait for confirmation before continuing.
- After the user confirms browser login, rerun:
e-mail-agent-cli doctor --provider m365 --json
- Only after
doctorshowsauthenticated: truemay the agent continue to mailbox operations. - If the user needs a shared mailbox, verify it explicitly:
e-mail-agent-cli doctor --provider m365 --mailbox admin@codecell.de --json
- For normal mailbox commands after login, do not rerun the device-code flow again. The CLI reuses the persisted session automatically.
- Use
auth exportonly when another shell process explicitly needs env exports:e-mail-agent-cli auth export m365 --write-env-file ~/.config/e-mail-agent-cli/m365.env
- If Microsoft permissions changed and the user must re-consent, rerun login with:
e-mail-agent-cli auth login m365 --persist --force
Shared mailbox onboarding
If the task involves shared or delegated mailboxes, the agent must confirm both sides of access:
- Microsoft Graph delegated permissions in the app registration:
Mail.ReadWrite.SharedMail.Send.Sharedfor sending
- real Exchange mailbox rights for the signed-in Microsoft 365 user
If doctor --mailbox <address> fails with a permission error, stop and tell the user that shared-mailbox setup is still incomplete.
Do not brute-force around that state with raw /users/... requests.
Core workflow
- Validate the environment:
e-mail-agent-cli auth status m365 --jsone-mail-agent-cli doctor --provider m365 --json- shared mailbox:
e-mail-agent-cli doctor --provider m365 --mailbox admin@codecell.de --json
- Inspect folders:
e-mail-agent-cli folders list --provider m365 --json- shared mailbox:
e-mail-agent-cli folders list --provider m365 --mailbox admin@codecell.de --json
- Search messages:
e-mail-agent-cli mail search --provider m365 --query "invoice" --limit 25 --body-format text --json- shared mailbox:
e-mail-agent-cli mail search --provider m365 --mailbox admin@codecell.de --query "invoice" --limit 25 --body-format text --json
- Read one message:
e-mail-agent-cli mail show --provider m365 --id <message-id> --body-format text --json- shared mailbox:
e-mail-agent-cli mail show --provider m365 --mailbox admin@codecell.de --id <message-id> --body-format text --json
- Use drafts for safer outbound workflows:
e-mail-agent-cli draft create ...e-mail-agent-cli draft update ...e-mail-agent-cli draft send --id <draft-id> --execute --confirm-send yes- shared mailbox drafts: pass
--mailbox <address>
Guardrails
- Read operations are safe by default.
- Draft creation and update are allowed directly.
- Sending requires explicit confirmation:
--execute --confirm-send yes
- In first-run situations, onboarding beats productivity:
- setup guide first
- static values second
- browser login third
doctorfourth- mailbox commands only after that
--mailboxis the preferred shared-mailbox switch. Prefer it over raw/users/...Graph paths.- Tokens can be exported into shell env files when explicitly requested. Never paste token values into issue trackers, chats, or agent prompts.
- Normal CLI usage should rely on the persisted local session. Do not insist on
eval "$( ... )"for every command. auth loginpersists the session by default.auth exportis the explicit bridge into shell env files.- Never ask the user for a client secret in the current Microsoft 365 CLI flow.
- Keep permissions narrow when possible. If a tenant does not need shared mailboxes, it can override
EMAIL_AGENT_M365_SCOPEwith a narrower value. - Move, archive, and mark-read operations require:
--execute
- Delete is intentionally not exposed in the first release.
- Prefer high-level commands over raw Graph requests.
- Use
graph requestonly for diagnostics or unsupported edge cases.
References
- Agent onboarding runbook:
references/agent-onboarding.md - Main overview:
references/overview.md - Command cheat sheet:
references/command-cheatsheet.md - First-run Microsoft 365 setup:
references/m365-first-run.md - Architecture:
knowledge/ARCHITECTURE.md - Auth notes:
knowledge/MICROSOFT_GRAPH_AUTH.md - Capability notes:
knowledge/MICROSOFT_GRAPH_CAPABILITIES.md