Skip to content
github-actions[bot] edited this page Dec 4, 2026 · 1 revision

Managing OwnMail from AI programs

OwnMail's administration can be used from AI programs (Claude Code, Cursor, Claude Desktop and other programs that speak the Model Context Protocol) and from your own scripts, with an access token, or by signing in from programs that connect by address only (claude.ai, ChatGPT; see Connecting by signing in):

Address What
https://<mail server name>/api/mcp the administration for AI programs (this page)
https://<mail server name>/api/... the administration API, for scripts
https://<mail server name>/mcp one mailbox's mail for AI programs, with an app password (see Usage)

The two MCP endpoints are separate. /api/mcp manages the server (domains, mailboxes, aliases, organisations, settings, backups) and never reads mail. /mcp works on the mail of one mailbox and never changes the server.

Access tokens

An access token acts as the administrator who made it: one who manages only some domains makes tokens that reach only those domains, and the tools about the server itself (settings, backups, health, mail traffic, activity) answer that only administrators of the whole server can use them. Make one in the administration under Access tokens → Add access token:

  • Name: which program uses it. It shows in the activity log, e.g. "admin@example.com via token AI assistant added the domain example.com".
  • What it may do: Read only (look at domains, mailboxes, records, settings, health, backups and the activity log) or Read and change (everything an administrator can do through the tools below).
  • May forward mail to outside addresses (only with Read and change, off unless you tick it): whether the token may make a mailbox forward, or a forwarding address deliver, to an address outside this server's domains. Without it, such a change answers that the token may not send mail on to outside addresses; targets that were set before may stay (renaming a forwarding address, keeping a forwarding that is on already). Someone who gets hold of a token could otherwise quietly send a mailbox's future mail to themselves. Tokens made before this choice existed keep it allowed; the list of tokens shows what each may do.
  • Stops working after 30 days, 90 days, 1 year or never.

The token (oma_…) is shown once, right after it is made. OwnMail stores only a hash of it. Delete cuts every program using it off at once (they get 401). Removing an administrator deletes their tokens.

Changing your password does not revoke your tokens. A token belongs to one program and is revoked on its own, so changing the password (for example on a schedule) does not cut off every program. If you change it because someone else may have known it, look through Access tokens: the list shows when each token was made and last used, and the activity log records every token added ("added the access token …"). Delete the ones you don't recognise.

What a token never does, whatever its access:

  • manage access tokens or administrators, or change the password: that needs signing in with the password in the browser, so a leaked token cannot make itself new ones;
  • take or show passwords: setting a mailbox's password, making app passwords, giving a new or shared mailbox a password, and switching "mail programs only with app passwords" need an administrator signed in with the password, also on the API (403 with a token). A personal mailbox made with create_mailbox gets a random password nobody knows (the answer says needs_password); set its password in the web interface before the person signs in;
  • turn off a mailbox's two-factor sign-in: it takes away a protection of the mailbox, so it needs an administrator signed in with the password (403 with a token); get_mailbox shows whether it is on (usage.two_factor);
  • read mail, import or export mailboxes, or restore one from a backup (also refused on the API);
  • add, change or remove a backup target (also its parts, schedule and keeping), leave a mailbox out of backups, or show the recovery key (see Backups);
  • change DNS records: OwnMail never does. get_mail_records lists what to enter at the DNS provider and checks it live.

The session cookie of the browser is never accepted at /api/mcp, and requests that browsers send from other web sites are refused.

API for tokens (signed in with the password, not with a token):

Method Path What
GET /api/tokens your tokens: name, access, created, last used, expiry; never the token
POST /api/tokens {"name", "access": "read"|"write", "expires_in_days": 1–3650 or null, "may_forward_outside": false}; the answer has the token in token, once
DELETE /api/tokens/{id} delete (revoke) one of your tokens

Connecting an AI program

Give the program the address and the token as a bearer token. For Claude Code:

claude mcp add --transport http ownmail https://mail.example.com/api/mcp \
  --header "Authorization: Bearer oma_…"

Most other programs take a setting like this:

{"mcpServers": {"ownmail": {"type": "http", "url": "https://mail.example.com/api/mcp",
  "headers": {"Authorization": "Bearer oma_…"}}}}

Connecting by signing in (claude.ai, ChatGPT)

Programs that connect by address only, such as connectors in claude.ai or ChatGPT, sign in instead of using a token (OAuth):

  1. In the program, add https://<mail server name>/api/mcp as a connector (in claude.ai under Settings → Connectors → Add custom connector, in ChatGPT as a connector in developer mode).
  2. The program sends you to OwnMail. Sign in as an administrator (with your second step, if it is on).
  3. OwnMail asks whether to connect the program, with the name the program gives itself and where you go back to. Choose Read only or Read and change, and with the latter whether it May forward mail to outside addresses (off unless you tick it), as for a token. Connect sends you back to the program; Don't connect refuses.

The program then acts as you, like a token with what you chose: it can't do what a token can't (see above), and the activity log names it ("admin@example.com via program Claude added …"). Its access lasts an hour and is renewed by the program for up to 30 days of not being used; connecting the same program again doesn't ask again. Access tokens → Connected programs lists the programs you connected; Disconnect cuts one off at once. Each administrator sees only their own. Programs that registered themselves but were never connected are removed after a day.

The program finds OwnMail's sign-in on its own: /api/mcp answers 401 with the address of its description (/.well-known/oauth-protected-resource/api/mcp), which names the authorization server https://<mail server name>/api/oauth (description at /.well-known/oauth-authorization-server/api/oauth, endpoints below /api/oauth/oauth2/). Programs may register themselves (at most 20 per address and hour) or identify themselves by the address of their own description. Only sign-in with PKCE is offered, and tokens are only valid for /api/mcp of this server name: after changing the mail server's name, connect the programs again. The administration API (/api/...) takes only access tokens.

API for connected programs (signed in with the password, not with a token):

Method Path What
GET /api/connect/programs the programs you connected: name, access, whether they may forward outside, when
POST /api/connect/programs/disconnect {"id": "…"}: disconnect one
GET/POST /api/connect/requests/{id} the consent page: the program asking, and {"accept", "access", "may_forward_outside"} → {"redirect_to"}

Scripts

Every route of the administration API accepts the token instead of the session cookie, without the X-Ownmail-Request header:

T='Authorization: Bearer oma_…'
curl -H "$T" https://mail.example.com/api/mail/domains
curl -H "$T" -X POST https://mail.example.com/api/mail/domains -d '{"domain":"example.com"}'

A token that does not work is answered 401 with WWW-Authenticate: Bearer, never as if nobody had sent one. A read-only token gets 403 for changes, and its check of a domain (POST /api/mail/domains/{domain}/check, check_mail_domain) only shows the domain as it is, without activating it.

Tools

Destructive tools ask to repeat the name of what they delete (confirm_domain, confirm_address, confirm_name). Out-of-office and forwarding set here are shown to the person as set by an administrator; if the person wrote their filters in a mail program, the call fails until replace is set with the user's agreement.

Server

Tool What
get_mail_status whether the mail service runs and is up to date, ports, certificate, queue, settings for mail programs
get_mail_traffic how much mail was received, sent, turned away, put in junk and bounced in the last 24 hours or 7 days, totals and per hour; only counts
get_mail_health what decides whether mail from this server is accepted elsewhere (name, SPF, reverse name, port 25, certificate, ports, postmaster, blocklists, the server's addresses on blocklists)
get_settings, update_settings the mail server's name, public addresses, postmaster address, certificate notices, blocklists, junk score, greylisting, the checking service for test messages
list_activity the activity log, newest first
get_update_status the running version, whether a newer one is out (with what changed), how this server updates and how the last update went; read only, updates are started in the web interface (Updates)

Domains and records

Tool What
list_mail_domains domains with whether they receive mail and why not
enable_mail_domain add a domain
get_mail_records the DNS records to enter (MX, SPF, DKIM, DMARC, SRV, autoconfig), checked live, and the reverse name
check_deliverability, get_deliverability_check send a test message from a domain to a checking service, and read its answer: SPF, DKIM, DMARC, the sender's name and the spam verdict as another server saw them
get_tls_reports what other mail servers reported in the last 30 days about delivering to a domain encrypted: connections encrypted, failed, and why
check_mail_domain look at the MX record now and activate the domain if it points here
activate_mail_domain receive mail before the MX record points here (gateways, split DNS)
delete_mail_domain delete a domain with every mailbox and all mail

Mailboxes

Tool What
list_mailboxes, get_mailbox mailboxes with kind, limits, usage, blocks, sharing and whether two-factor sign-in is on
create_mailbox personal, shared, or a room or equipment
set_mailbox_limits quota and send limits
set_mailbox_display_name the name shown as sender
unblock_mailbox let a mailbox the server blocked send again
delete_mailbox delete a mailbox and all its mail
get_mailbox_setup what to enter in a mail program
list_mail_imports, cancel_mail_import imports (they are started in the web interface)

Aliases and organisations

Tool What
list_mail_aliases, set_mail_alias, delete_mail_alias forwarding addresses, distribution groups, catch-all
list_mail_organisations, set_mail_organisation, delete_mail_organisation groups of domains whose mailboxes can share
set_mail_domain_organisation put a domain into an organisation or let it stand alone

Sharing

Tool What
set_mailbox_kind make a mailbox shared or a room or equipment; keep a copy of sent mail
set_mailbox_access, remove_mailbox_access who may use a shared mailbox and how
set_resource_booking booking rules of a room or equipment

Out-of-office and forwarding

Tool What
get_mailbox_rules out-of-office and forwarding of a mailbox and who set them
set_mailbox_out_of_office, clear_mailbox_out_of_office the automatic reply
set_mailbox_forwarding, clear_mailbox_forwarding forward all mail to another address
set_mailbox_may_forward allow or forbid any forwarding of a mailbox

AI programs and app passwords

Tool What
set_mail_domain_ai_access, set_mailbox_ai_access whether mailboxes may be used from AI programs at /mcp
set_mail_domain_client_host a mail domain's own name for mail programs (e.g. mail.example.com), see Usage
list_mailbox_app_passwords, revoke_mailbox_app_password app passwords of a mailbox (made in the web interface)

Backups

Tool What
backup_status backup targets: where backups go (never credentials), what they hold, schedule, which are kept, last run, last run that worked, next run, whether one runs now and how far it is, overdue
list_backup_runs the runs of a target, newest first, with result, size and errors
list_backup_snapshots the backups stored on a target (connects to it, can take a while)
run_backup_now start a backup to a target now, or right after the one under way
list_mailbox_backups the backups a mailbox can be restored from
get_mailbox_restore how a mailbox's restore is going, or how the last one ended

A read-only token can use the tools that look (backup_status, list_backup_runs, list_backup_snapshots, list_mailbox_backups, get_mailbox_restore); starting a backup needs a token that may change. Some things about backups are never done with a token, so there are no tools for them (the API refuses tokens as well, 403):

  • adding a backup target, changing where one leads or testing new settings: a target is where all mail and the server's key go, so a token could otherwise copy every mailbox out;
  • what a target keeps: its parts, schedule and keeping, removing it, and leaving a mailbox out of backups. Backing up less (or leaving a mailbox out) and keeping only the newest backup would let the next run remove every backup of the mail; these are done in the web interface;
  • the recovery key: it opens every backup, and is shown only to an administrator signed in with the password;
  • restoring a mailbox: a restore fills a mailbox with mail from a backup, which access tokens never do, just as they never import mail. Start it in the web interface on the mailbox's page; a program can follow it with get_mailbox_restore.

Home

Running OwnMail

Using OwnMail

How it is built

Taking part

Clone this wiki locally