My agentic slop goes here. Not intended for anyone else!

Query 6: Recent Emails Sent to Company Domain#

Use Case Description#

Find emails sent to colleagues within the company domain in the last 30 days. This demonstrates EmailSubmission queries, domain-based filtering, and tracking of outgoing communications.

Key JMAP Concepts Used#

  • EmailSubmission/query: Tracking sent emails via submission records
  • Domain filtering: Using email address patterns to match company domain
  • Sent mailbox discovery: Finding sent items via mailbox role
  • Date range filtering: Recent activity within time window
  • Submission status tracking: Understanding email delivery states

JMAP Request#

{
  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
  "methodCalls": [
    [
      "Mailbox/query",
      {
        "accountId": "u12345678",
        "filter": {
          "role": "sent"
        }
      },
      "mb0"
    ],
    [
      "EmailSubmission/query",
      {
        "accountId": "u12345678",
        "filter": {
          "operator": "AND", 
          "conditions": [
            {
              "after": "2024-07-25T00:00:00Z"
            },
            {
              "operator": "OR",
              "conditions": [
                {
                  "to": "*@mycompany.com"
                },
                {
                  "cc": "*@mycompany.com" 
                },
                {
                  "bcc": "*@mycompany.com"
                }
              ]
            }
          ]
        },
        "sort": [
          {
            "property": "created",
            "isAscending": false
          }
        ],
        "limit": 25
      },
      "sub0"
    ],
    [
      "EmailSubmission/get",
      {
        "accountId": "u12345678",
        "#ids": {
          "resultOf": "sub0",
          "name": "EmailSubmission/query",
          "path": "/ids"
        },
        "properties": [
          "id", "emailId", "identityId", "envelope", "created",
          "deliveryStatus", "dsnBlobIds", "mdnBlobIds"
        ]
      },
      "subg0" 
    ],
    [
      "Email/get",
      {
        "accountId": "u12345678",
        "#ids": {
          "resultOf": "subg0",
          "name": "EmailSubmission/get", 
          "path": "/list/*/emailId"
        },
        "properties": [
          "id", "from", "to", "cc", "bcc", "subject", "sentAt",
          "preview", "hasAttachment", "threadId"
        ]
      },
      "eg0"
    ]
  ]
}

Expected Response Structure#

{
  "methodResponses": [
    [
      "Mailbox/query",
      {
        "accountId": "u12345678", 
        "queryState": "mq1234567894",
        "canCalculateChanges": true,
        "position": 0,
        "ids": ["Msent"],
        "total": 1,
        "limit": null
      },
      "mb0"
    ],
    [
      "EmailSubmission/query",
      {
        "accountId": "u12345678",
        "queryState": "sq1234567894", 
        "canCalculateChanges": true,
        "position": 0,
        "ids": ["ES123", "ES124", "ES125"],
        "total": 18,
        "limit": 25
      },
      "sub0"
    ],
    [
      "EmailSubmission/get",
      {
        "accountId": "u12345678",
        "state": "s9876543215",
        "list": [
          {
            "id": "ES123",
            "emailId": "Memail301",
            "identityId": "I1",
            "envelope": {
              "mailFrom": "john.doe@mycompany.com",
              "rcptTo": ["alice.smith@mycompany.com", "bob.jones@mycompany.com"]
            },
            "created": "2024-08-23T14:30:00Z",
            "deliveryStatus": {
              "alice.smith@mycompany.com": "delivered",
              "bob.jones@mycompany.com": "delivered"
            },
            "dsnBlobIds": null,
            "mdnBlobIds": null
          },
          {
            "id": "ES124", 
            "emailId": "Memail302",
            "identityId": "I1",
            "envelope": {
              "mailFrom": "john.doe@mycompany.com",
              "rcptTo": ["team@mycompany.com"]
            },
            "created": "2024-08-22T16:15:00Z",
            "deliveryStatus": {
              "team@mycompany.com": "delivered"
            },
            "dsnBlobIds": null,
            "mdnBlobIds": null
          }
        ],
        "notFound": []
      },
      "subg0"
    ],
    [
      "Email/get",
      {
        "accountId": "u12345678",
        "state": "s9876543215",
        "list": [
          {
            "id": "Memail301",
            "from": [{"email": "john.doe@mycompany.com", "name": "John Doe"}],
            "to": [
              {"email": "alice.smith@mycompany.com", "name": "Alice Smith"},
              {"email": "bob.jones@mycompany.com", "name": "Bob Jones"}
            ],
            "cc": [],
            "bcc": [],
            "subject": "Weekly Team Sync - Action Items",
            "sentAt": "2024-08-23T14:30:00Z", 
            "preview": "Hi team, Here's a summary of our action items from today's meeting...",
            "hasAttachment": false,
            "threadId": "Tthread501"
          },
          {
            "id": "Memail302",
            "from": [{"email": "john.doe@mycompany.com", "name": "John Doe"}],
            "to": [{"email": "team@mycompany.com", "name": "Engineering Team"}],
            "cc": [],
            "bcc": [],
            "subject": "Code Review Guidelines Update",
            "sentAt": "2024-08-22T16:15:00Z",
            "preview": "Team, I've updated our code review guidelines based on recent feedback...",
            "hasAttachment": false,
            "threadId": "Tthread502"
          }
        ],
        "notFound": []
      },
      "eg0"
    ]
  ]
}

Explanation of Key Features#

EmailSubmission vs Email Objects#

  • EmailSubmission: Tracks the sending process and delivery status
  • Email: Contains message content and threading information
  • EmailSubmission links to Email via emailId property
  • Both objects provide different perspectives on sent messages

Domain-Based Filtering#

{
  "operator": "OR",
  "conditions": [
    {"to": "*@mycompany.com"},
    {"cc": "*@mycompany.com"},
    {"bcc": "*@mycompany.com"}
  ]
}
  • Wildcard pattern *@mycompany.com matches any user at company domain
  • OR operator catches emails where any recipient field contains company addresses
  • Handles mixed internal/external recipient lists

Submission Envelope Information#

  • envelope.mailFrom: SMTP sender address (may differ from From header)
  • envelope.rcptTo: Actual SMTP recipients (includes Bcc addresses)
  • deliveryStatus: Per-recipient delivery outcomes
  • created: When submission was initiated (vs email sentAt)

Delivery Status Tracking#

Possible deliveryStatus values:

  • "queued": Accepted for delivery but not yet sent
  • "delivered": Successfully delivered to recipient
  • "failed": Permanent delivery failure
  • "deferred": Temporary failure, retry scheduled
  • "unknown": Status not available

Advanced Submission Queries#

Failed Deliveries:

{
  "operator": "AND",
  "conditions": [
    {"after": "2024-08-20T00:00:00Z"},
    {"deliveryStatus": "failed"}
  ]
}

Specific Identity Usage:

{
  "operator": "AND", 
  "conditions": [
    {"identityId": "I2"},
    {"after": "2024-08-01T00:00:00Z"}
  ]
}

High-Priority Submissions:

{
  "operator": "AND",
  "conditions": [
    {"envelope/rcptTo": "*@vip-client.com"},
    {"deliveryStatus": "queued"}
  ]
}

Business Intelligence Use Cases#

This query pattern enables:

  • Communication auditing: Track internal vs external communications
  • Collaboration analysis: Identify team communication patterns
  • Delivery monitoring: Ensure critical messages reach colleagues
  • Identity usage: Understand which sending identities are used when
  • Compliance reporting: Document internal communication for compliance
  • Network analysis: Build organizational communication graphs

Integration with Email Analytics#

  • Combine EmailSubmission delivery data with Email engagement metrics
  • Track which internal emails generate replies (thread analysis)
  • Monitor response times within organization
  • Identify communication bottlenecks or missed messages
  • Analyze meeting scheduling and follow-up patterns