Guides

Send and receive mail

Read and send mail from an Identity’s Mailbox, and understand who it may write to.

Every Identity has a real mailbox: orderbot@tigby.eu, receiving from anyone, readable over REST and IMAP.

Read

curl -H "Authorization: Bearer $TIGBY_API_KEY" \
  https://api.tigby.eu/api/identities/orderbot/messages

Newest first, with sender, subject, preview, the subaddress tag the message came in on, and the origin verdict recorded on delivery: DMARC alignment, falling back to SPF on the return path. GET /api/identities/orderbot/messages/{id} returns one message with headers and decoded bodies.

Both read the Inbox. Mail the spam filter files to Junk is not listed and not readable by id, and neither is a message an IMAP client deleted; a mail client's delete moves the message to Trash rather than removing it. Everything the mailbox holds, each message labelled with the folder it was in, is in the data export.

From the CLI

tigby email list @orderbot
tigby email read @orderbot {id}

Anyone can write to the Mailbox, so the CLI's table and message view print what a sender wrote with every character a terminal would act on (escape sequences, other control characters, line and paragraph separators, Bidi overrides) replaced by �. Newlines and tabs in a body stay; a header and a table cell stay on one line. This holds whether the output goes to a terminal, a file or a pipe. --json is the byte-faithful path: it prints the API's answer exactly as it came, with those characters escaped by JSON, so a script gets what the sender sent and is the one to decide how to show it.

Tags

The Mailbox also receives on orderbot+shop@tigby.eu. Use one tag per service the agent signs up to, and the agent can tell them apart by the tag on each message.

IMAP

The per-mailbox password is handed over by GET /api/identities/orderbot/identity-key, the same call that hands over the first Identity Key, and never the status read. It stays readable until you acknowledge it or its short window closes; after that only its hash remains. Lost it? POST /api/identities/orderbot/mailbox/password sets a new one and returns it, the only response that ever carries it.

Archive and delete

curl -X POST -H "Authorization: Bearer $TIGBY_API_KEY" \
  https://api.tigby.eu/api/identities/orderbot/messages/{id}/archive
curl -X DELETE -H "Authorization: Bearer $TIGBY_API_KEY" \
  https://api.tigby.eu/api/identities/orderbot/messages/{id}

Archive moves a message out of the Inbox into the Mailbox's Archive folder; the first archive makes that folder, in a new Mailbox and an older one alike. Delete moves it to Trash, as a mail client's delete does: nothing in the API brings it back, and the mail server removes what has been in Trash for 30 days. A message a person also filed in a folder of their own is the exception: delete only takes it out of the Inbox and leaves it where they filed it, because the Trash expiry would delete it from every folder at once.

Either way the message leaves the list and the read, a mail client sees it where it went, and while it is there the data export carries it with that folder's label. Both answer 204, also when the message has already left the Inbox, so a retry is safe.

Several Instances on one Mailbox

Every Instance of the Identity reads the same Mailbox, so two of them see the same new message, and without something between them, both answer it. That something is the claim: an Instance claims a message before it works on it, and the first claim wins.

# The mail nobody has claimed yet.
curl -H "Authorization: Bearer $TIGBY_API_KEY" \
  "https://api.tigby.eu/api/identities/orderbot/messages?claimed=false"

# Take one before working on it.
curl -X POST -H "Authorization: Bearer $TIGBY_API_KEY" \
  https://api.tigby.eu/api/identities/orderbot/messages/{id}/claim

The claim that wins answers 200 with the claim. Every later one (from another Instance, or from the same one retrying) is refused with 409 message_claimed, and the refusal says when the standing claim was made and under which key. Leave that message; another Instance has it. When you are done, archive the message: that takes the claim with it, and the Inbox stays the mail still to handle.

The claim is on the list and the read, as claim: claimed_at, claimed_by (identity_key, admin_key, or session for the console), and the key's key_id and key_name. A message nobody has claimed has no claim. claimed=true lists only claimed messages and claimed=false only the others. A claimed message moved out of the Inbox over IMAP keeps its claim, and it is listed again once it is back; a claimed message deleted for good outside Tigby (over IMAP, or emptied from Trash) loses its claim at the next claimed=true read, so it does not count towards that list's limit of 5,000 claims.

Filtering costs

claimed=false is the expensive one. The mail server knows nothing of claims, so Tigby reads every Inbox message that matches query to answer it (one request per 500 messages, out of a budget of 1,000 requests a minute that the mail server gives the whole Mailbox, every Instance together) and refuses with message_filter_too_broad above 5,000. Archive what is done, and poll no more than every 30 seconds.

The list without claimed costs two requests however large the Inbox is, and its first page shows each message's claim, so an Instance that only wants the newest unclaimed mail can read that and skip what carries a claim. A Webhook for email.received tells your Instances when there is something to look at.

Release a claim

A claim has no lease and does not run out. DELETE /api/identities/orderbot/messages/{id}/claim releases it, whoever made it: that is how a claim a crashed Instance left behind is reopened. Read its claimed_at and key first; releasing a claim an Instance is still working on is how one mail gets answered twice.

Give each Instance that claims mail its own Identity Key (Keys). The claim names the key, so two Instances sharing one cannot tell their own claim from each other's.

A claim is Tigby's own record and not a flag on the message. It does not mark the message read, and a person reading the Mailbox in a mail client (opening a message, marking it read) neither makes nor clears one.

Sessions that are not one agent

Several harness sessions on one Identity are Instances too, but often each does its own work: one signs up to a shop, another to a newsletter. Give each session a tag of its own and the address with it (orderbot+session-7@tigby.eu) and have it read its own mail:

curl -G -H "Authorization: Bearer $TIGBY_API_KEY" \
  --data-urlencode "query=orderbot+session-7@tigby.eu" \
  https://api.tigby.eu/api/identities/orderbot/messages

The mail server finds the address among a message's recipients, and every message carries its tag to check. A message that reached the address only as a blind copy carries the tag and is not found by the query, because the address is nowhere in it but in the delivery.

Handing mail out by Webhook

Tigby is not a queue: it does not assign a message to one Instance. A Webhook for email.received pointed at the Identity's own Tunnel does the handing out. Each delivery opens a connection of its own, and the Tunnel gives each connection to one connected Instance, so each message reaches one of them.

Have that Instance claim the message before it works on it, as above. A delivery is made at least once, so a retry can bring the same evt_ id again. The claim is what stops a second Instance, or a second delivery, from answering the same mail twice.

Two cases delay a delivery. If no Instance is connected, the Tunnel answers 503 tunnel_offline and the delivery is retried on the published schedule. While Tigby fails over from one server to the other, deliveries pause for a few minutes and then go out.

Send

curl -X POST -H "Authorization: Bearer $TIGBY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to": ["anna@kunde.de"], "subject": "Order 4711", "text": "…"}' \
  https://api.tigby.eu/api/identities/orderbot/messages/send

Every send (REST or SMTP) passes the same policy point: the recipient must be an Allowed Recipient, and the Org's send limit must have room. A refusal carries the same stable code on both doors, plus an email.recipient_blocked Event.

To answer a message, send its Message-ID in in_reply_to, and the thread's earlier ones in references, one per entry, each as the message read reports it in its message_id list, with or without angle brackets. Both go into the message's headers as they stand, so each has to be one Message-ID: text, one @ and text, with no space or line break. Anything else is refused with 400 message_id_invalid before anything is sent.

Sending as the Mailbox

A Mailbox sends as itself and as nobody else. A REST send has no sender to set: Tigby writes the From header. A mail client that submits over SMTP with the Mailbox password writes its own, and Tigby holds it to the same rule:

  • The envelope sender and the message's From header are the Mailbox's own address: orderbot@tigby.eu, or that address with a tag, orderbot+shop@tigby.eu.
  • There is exactly one From header, and every address in it is the Mailbox's.
  • A Sender header, if the client writes one, names the same address.
  • The display name is yours to choose, and so is Reply-To.

Anything else is refused with sender_mismatch and nothing is sent: another address in From or Sender, a second From header, or a From that is missing or does not parse. Tigby reads the header as a strict receiver does, so a display name that contains a comma, an @ or square brackets has to be in quotes: "Miller, Ann" <orderbot@tigby.eu> passes and Miller, Ann <orderbot@tigby.eu> is refused.

Tigby never rewrites the header to make a message pass.

Retrying a send safely

A send whose answer never arrived (a timeout, a dropped connection, a 503) may or may not have gone out. Send an Idempotency-Key header with every send, and a retry cannot become a second mail:

curl -X POST -H "Authorization: Bearer $TIGBY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 5f0c2a9e-7b1d-4c3e-9a8f-2d6b1e4c7a90" \
  -d '{"to": ["anna@kunde.de"], "subject": "Order 4711", "text": "…"}' \
  https://api.tigby.eu/api/identities/orderbot/messages/send
  • One key per mail. Use a fresh key (a UUID) for every mail you mean to send, and the same key for every retry of it. A key is 1 to 255 visible ASCII characters and belongs to the Identity, so two Identities never meet on one.
  • A repeat of a send that went out answers 202 with the first send's message_id for 24 hours. It sends nothing, and it counts against no limit and spends no allowance or Credit.
  • The same key with another body is refused with idempotency_key_reused (422). The body is compared as the API reads it, so another key order or an empty cc left out is the same body.
  • A refused send leaves the key free. After recipient_not_allowed, mail_paused, send_limit_reached, send_allowance_spent, send_rejected, or a 503 that says nothing was sent, send the same request with the same key once the cause is gone.
  • When the outcome is unknown: The 503 means the submission broke off. The key is held for a few minutes, and a repeat meanwhile is answered idempotency_key_in_progress (409) with a Retry-After. After that the repeat finds out: it answers with the message_id if the mail went out, and sends it if it did not.
  • Two Instances sending one key at once get one mail between them: one sends, the other is told idempotency_key_in_progress and gets the same message_id when it retries.

The tigby_email_send MCP Tool takes the key as its idempotency_key argument, and both SDKs take it as an optional argument of the send.

Allowed Recipients

Outbound mail goes only to addresses or domains on the allowlist; inbound is never restricted. Entries come from two sources:

  • Manual: an Admin Key adds an address (anna@kunde.de) or a domain (@kunde.de) on POST /api/allowed-recipients. Permanent, counted against the Plan. Freemail and disposable domains are refused as whole domains.
  • Automatic: a sender whose mail reached the Identity and proved its origin is granted back automatically. Expiring, refreshed by each further verified mail, uncounted.

Mail another Tigby Identity sends to yours arrives like any other mail and raises email.received (whose from is then the address of the Mailbox that sent it, not whatever its From header claims) but grants nothing automatically: nothing sent from inside Tigby widens a list, so to reply, add the sender with an Admin Key. Tigby's own mail (a sign-in link, a service notice) raises no Event and never lands on a list.

The agent itself can read the list, never change it.

Outbound agent mail is marked as coming from an AI agent by default (EU AI Act, Art. 50). Switching it off requires an explicit acknowledgement in the request and is recorded as an Event either way.