# POST /domains/{name}/mail/accounts/{local}/bot-keys

First published 18 Oct 2026 (release 0.2.10) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the mail group.

Create a bot key for a mailbox

- Who may call it: administrator, reseller, customer
- Token scope, any of: mail, all
- Answers: 201 Created

Creates a named key and returns it in key. The 201 response reveals the secret only once, both on its own and as part of the MCP URL to give the bot. The caller must have access to the domain, BotMail must be ready for that domain, and the customer's package must allow BotMail. A missing mailbox returns 404.

When creating the mailbox's first key, set used_by_person to true if a person also uses the mailbox in a mail client or to false if only bots use it. The default is true. This mailbox setting supplies defaults for new keys. For a shared mailbox, send_mode defaults to drafts, outgoing mail stays in Drafts, and the key cannot access Drafts or Trash by default. For a bots-only mailbox, send_mode defaults to self, which allows direct sending. By default, the key cannot access Trash, and copies of outgoing mail go to the customer's email address if one is set.

The platform field records the bot's platform. The from_name field sets the sender display name. An empty from_name uses only the sender's email address. The may field accepts read,search,flag,draft,send,reply and defaults to read,search. The send_mode field accepts self, drafts, or known. The folders_out field lists folders the key cannot access and accepts drafts,sent,junk,trash. The recipients and blocked fields accept email addresses or domain names, such as a@b,example.com. The copy_to field gives the email address that receives copies of outgoing mail. The from_addresses field restricts access to the listed IP addresses or CIDR networks. List values can be arrays or comma-separated strings. A rule value returns 400 if it contains control characters or exceeds 4096 characters in its text form, after joining any list entries with commas. The expires_days field sets the key's lifetime in days and defaults to 0 for no expiration.

The sends_per_hour field defaults to 20 and accepts 1 to 1000. The recipients_per_message field defaults to 5 and accepts 1 to 50. The sends_per_day and calls_per_minute fields default to 100 and 30, respectively, and both have a minimum of 1. Their maximums are set by mail.botmail_sends_per_day and mail.botmail_calls_per_minute, which default to 200 and 60, respectively. The mail.botmail_keys_per_mailbox setting defaults to 5. A package can set a lower key limit per mailbox. An unset or zero package limit uses the server ceiling.

## As a command

- [urbestack-botmail-key-add](https://urbestack.com/docs/commands/urbestack-botmail-key-add.md): Creates a named BotMail key for the mailbox specified by --address.

## Parameters

- `name` (path, DomainName, required)
- `local` (path, LocalPart, required)

## Request body

JSON, the type [BotKeyCreate](https://urbestack.com/docs/api/types/BotKeyCreate.md).

- `name` (string, up to 64 characters, required): Name the mailbox owner gives the key.
- `blocked` (array of string, up to 254 characters): Email addresses and domains the key can never send to.
- `calls_per_minute` (integer, 1 to 6000): Maximum number of calls per minute, subject to the server's ceiling.
- `copy_to` (string, up to 320 characters or null): Email address that receives a copy of every message sent with the key. An empty string or null removes the email address.
- `expires_days` (integer, 0 to 3650): Number of days until the key expires. A value of 0 means it never expires.
- `folders_out` (array of string, one of drafts, sent, junk, trash): Special folders the key cannot access, chosen from drafts, sent, junk, and trash.
- `from_addresses` (array of string, up to 64 characters): Allowed source IP addresses or CIDR ranges for calls made with the key. An empty list allows calls from any IP address.
- `from_name` (string, up to 64 characters): Sender display name on messages sent with this key. An empty value uses the email address alone.
- `may` (array of string, one of read, search, flag, draft, send, reply): Actions the key permits, chosen from read, search, flag, draft, send, and reply. With reply alone, the bot can only answer messages it was given and cannot write to other recipients.
- `platform` (string, up to 32 characters): Label for where the bot runs, such as ChatGPT, Claude, or my program.
- `recipients` (array of string, up to 254 characters): Email addresses and domains the key can send to. An empty list imposes no recipient restriction.
- `recipients_per_message` (integer, 1 to 50)
- `send_mode` (string, one of self, drafts, known): Delivery mode for outgoing messages. Use self to send automatically, drafts to hold messages in the Drafts folder for the owner, or known to send to known contacts and hold the remaining messages in Drafts.
- `sends_per_day` (integer, 1 to 100000): Maximum number of sends per day, subject to the server's ceiling.
- `sends_per_hour` (integer, 1 to 1000)
- `used_by_person` (boolean): Whether a person also uses this mailbox in their own mail program. UrbeStack saves this value as a mailbox setting.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/domains/example.com/mail/accounts/info/bot-keys" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "blocked": [
      "text"
    ],
    "calls_per_minute": 1,
    "copy_to": "text",
    "expires_days": 1,
    "folders_out": [
      "drafts"
    ],
    "from_addresses": [
      "text"
    ],
    "from_name": "text",
    "may": [
      "read"
    ],
    "name": "alice",
    "platform": "text",
    "recipients": [
      "text"
    ],
    "recipients_per_message": 1,
    "send_mode": "self",
    "sends_per_day": 1,
    "sends_per_hour": 1,
    "used_by_person": true
  }'
```

Response, 201 Created:

```
{
  "key": {}
}
```

## Errors

- 400: --address is required
- 400: <k> holds a character a rule may not
- 400: A bot connector needs a label
- 400: Domain name required
- 400: Domain name too long
- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid boolean
- 400: Invalid domain name
- 400: Invalid mail address: local part over 64 characters
- 400: Invalid mail address: no local part
- 400: Invalid mail address: the local part may hold letters, digits, dots, _ + and -
- 400: Invalid port
- 400: Invalid setting key
- 401: Authentication required
- 403: The package <p.name> does not include <SWITCH_WHAT>{<switch>}
- 404: No such mail account: <address>
- 404: Setting '<key>' not found
- 409: BotMail is not on for <m.domain>: turn it on for the domain first
- 409: The mailbox <m.address> has <allowed> bot connectors already, the most a mailbox may have
