Optimaite

Email Inbound

3 min readUpdated May 27, 2026Auch auf Deutsch verfuegbar

The Email Inbound API handles incoming email from external mail services (Mailgun) and provides endpoints for the unified inbox.

Endpoints

MethodPathDescription
POST/api/v1/email/inboundReceive inbound email from Mailgun webhook
POST/api/v1/inbox/uploadUpload documents to the unified inbox
GET/api/v1/inbox/document/{id}/relatedGet related emails and documents for an inbox document

Required scope: inbox:read for read endpoints. The Mailgun inbound webhook uses HMAC signature verification, not API key auth.

Mailgun Webhook

POST /api/v1/email/inbound

This endpoint receives inbound email from Mailgun. It is authenticated via Mailgun's HMAC signature verification (not via API key). The system automatically:

  1. Parses the email (headers, body, attachments)
  2. Creates a correspondence record
  3. Extracts and stores attachments as documents
  4. Attempts to match the sender to an existing party
  5. Runs AI triage (category, priority, suggested assignment)

Request (from Mailgun)

The request body is application/x-www-form-urlencoded with Mailgun's standard fields:

FieldDescription
fromSender email address
toRecipient email address
subjectEmail subject line
body-plainPlain text body
body-htmlHTML body
attachment-NAttached files (multipart)
timestampMailgun timestamp
tokenMailgun token
signatureHMAC-SHA256 signature

Response

Returns 200 OK on successful processing. The system processes the email asynchronously.

Upload to Inbox

POST /api/v1/inbox/upload
Content-Type: multipart/form-data

Upload one or more documents directly to the unified inbox. Documents go through the same processing pipeline as emailed documents.

Form Fields

FieldTypeRequiredDescription
filesFile[]YesOne or more files to upload
sourcestringNoSource identifier (e.g., "scanner", "drag-drop")

Response

{
  "uploaded": [
    {
      "document_id": "doc_01ABCDEF",
      "filename": "contract.pdf",
      "status": "processing"
    }
  ]
}

Related Documents

GET /api/v1/inbox/document/{document_id}/related

Returns all emails and documents related to an inbox document -- emails from the same sender, documents in the same case, etc.

Response

{
  "emails": [
    {
      "id": "corr_01",
      "subject": "RE: Contract Review",
      "from": "client@example.com",
      "received_at": "2026-05-20T14:00:00Z"
    }
  ],
  "documents": [
    {
      "id": "doc_01ABCDEF",
      "filename": "contract_v2.pdf",
      "case_id": "550e8400-..."
    }
  ]
}

Next Steps

Was this helpful?