{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/groundmail-dev/json-schema/groundmail-dev-received-email-response-schema.json",
  "title": "ReceivedEmailResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/groundmail-dev-inbound-api-openapi.yml#/components/schemas/ReceivedEmailResponse",
  "type": "object",
  "required": [
    "received_email"
  ],
  "properties": {
    "received_email": {
      "$ref": "#/$defs/ReceivedEmail"
    }
  },
  "$defs": {
    "EmailTag": {
      "type": "object",
      "required": [
        "name",
        "value"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "value": {
          "type": "string"
        }
      }
    },
    "InReplyToEmail": {
      "type": "object",
      "description": "The sent email a received email replies to, as it was when the reply arrived.",
      "required": [
        "id",
        "subject",
        "from",
        "to",
        "sent_at",
        "tags",
        "tenant"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "The sent email's id (`msg_…`). Pass it to `GET /emails/{id}` while it is within data retention."
        },
        "subject": {
          "type": "string"
        },
        "from": {
          "type": "string"
        },
        "to": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "sent_at": {
          "type": "string",
          "format": "date-time"
        },
        "tags": {
          "type": "array",
          "description": "The email's tags as sent (`[]` when it had none).",
          "items": {
            "$ref": "#/$defs/EmailTag"
          }
        },
        "tenant": {
          "type": [
            "string",
            "null"
          ],
          "description": "The `external_id` of the tenant it was sent for; null when it was not sent as a tenant."
        }
      }
    },
    "ReceivedEmail": {
      "type": "object",
      "required": [
        "id",
        "domain_id",
        "domain_name",
        "status",
        "rcpt_to",
        "mail_from",
        "from",
        "to",
        "cc",
        "subject",
        "spam_status",
        "spam_score",
        "bounced",
        "received_with_ssl",
        "message_id",
        "in_reply_to",
        "references",
        "in_reply_to_email",
        "attachment_count",
        "attachments",
        "text_body",
        "html_body",
        "auto_submitted",
        "received_at",
        "created_at"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Received email public id (`inb_…`)"
        },
        "domain_id": {
          "type": "string"
        },
        "domain_name": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "received"
          ]
        },
        "rcpt_to": {
          "type": "string",
          "format": "email",
          "description": "Envelope recipient as received by Groundmail."
        },
        "mail_from": {
          "type": [
            "string",
            "null"
          ],
          "description": "SMTP envelope sender."
        },
        "from": {
          "type": "string"
        },
        "to": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "email"
          }
        },
        "cc": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "email"
          }
        },
        "subject": {
          "type": "string"
        },
        "spam_status": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "clean",
            "suspicious",
            "spam"
          ],
          "description": "Content scanning verdict: `spam` at or above the domain's spam threshold (default 10), `suspicious` from 5, else `clean`. Null when the message was not scanned."
        },
        "spam_score": {
          "type": [
            "number",
            "null"
          ],
          "description": "Content scanning score. Higher is more likely spam; most clean mail scores under 5. Null when not scanned."
        },
        "bounced": {
          "type": "boolean"
        },
        "received_with_ssl": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "message_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "in_reply_to": {
          "type": [
            "string",
            "null"
          ]
        },
        "references": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "in_reply_to_email": {
          "allOf": [
            {
              "$ref": "#/$defs/InReplyToEmail"
            }
          ],
          "nullable": true,
          "description": "The email you sent through Groundmail that this one replies to, matched by its `In-Reply-To` header, then `References`. A copy taken when the reply arrived, so it is still here after the sent email passes your plan's data retention. Null when the reply matches none of your sent emails."
        },
        "attachment_count": {
          "type": "integer"
        },
        "attachments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ReceivedEmailAttachment"
          }
        },
        "text_body": {
          "type": [
            "string",
            "null"
          ]
        },
        "html_body": {
          "type": [
            "string",
            "null"
          ]
        },
        "auto_submitted": {
          "type": [
            "string",
            "null"
          ]
        },
        "received_at": {
          "type": "string",
          "format": "date-time"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "ReceivedEmailAttachment": {
      "allOf": [
        {
          "$ref": "#/$defs/ReceivedEmailAttachmentMeta"
        },
        {
          "type": "object",
          "properties": {
            "data": {
              "type": "string",
              "format": "byte",
              "description": "Base64-encoded attachment content. Present on retrieve responses, omitted from list responses."
            }
          }
        }
      ]
    },
    "ReceivedEmailAttachmentMeta": {
      "type": "object",
      "required": [
        "filename",
        "content_type",
        "size"
      ],
      "properties": {
        "filename": {
          "type": "string"
        },
        "content_type": {
          "type": "string"
        },
        "size": {
          "type": "integer"
        },
        "content_id": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}