メールの受信:読み取り

Search

送信者、ドメイン、件名、本文、ラベルでメールボックスを検索します。Webmailの検索ボックスと同じ演算子が使えます。

POSThttps://g.sendcorex.com/v1command: search

fieldがない場合は自動判定です。完全なメールアドレスは送信者の完全一致、domain.comはドメイン、それ以外は件名、本文、送信者名で検索します。

演算子(from:、is:unread…)を使うと、結果は会話ごとにまとめられます(スレッドごとに1行、一致した最新のメッセージ)。in:がない場合、Spamとゴミ箱は除外されます。

引数

  • querystring必須

    検索語(256文字まで)。複数の語の場合、最初の語はインデックスから、残りは件名とプレビューで絞り込みます。

  • fieldstring任意

    通常の検索をfrom、to、subject、body、sender、labelに限定します。クエリに演算子がある場合は無視されます。

  • limitnumber任意

    ページサイズ(1〜100)。デフォルトは25。

  • cursorstring任意

    前のページのnext_cursor。

クイックスタート

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "search",
        args: {
          query: "ana@client.com",
          field: "from",
          limit: 5
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);

レスポンス

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "search",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "messages": [
          {
            "message_uid": "Vj0xQUJDMTIz",
            "thread_id": "thr_9a1c4e72",
            "subject": "Invoice for September",
            "preview": "Hi, attached is the invoice for September…",
            "from_name": "Ana Costa",
            "from_email": "ana@client.com",
            "folders": [
              "INBOX"
            ],
            "is_read": false,
            "is_starred": false,
            "is_important": false,
            "received_at": "2026-10-09T14:21:07Z"
          }
        ],
        "has_more": false,
        "next_cursor": null
      }
    }
  ]
}

レスポンスの項目

  • messages[]

    一致したメッセージ(新しい順)。それぞれmessage_uid、thread_id、subject、preview、from_name、from_email、folders、既読・スター・重要のフラグ、received_atを持ちます。

  • has_more / next_cursor

    ページネーション。

演算子

通常の語と組み合わせて使えます。空白を含む値は引用符で囲みます:subject:"new proposal"。除外するには先頭に-を付けます:-from:noreply、-newsletter。

リクエストボディ

{
  "commands": [
    {
      "command": "search",
      "args": {
        "query": "from:ana@client.com has:attachment newer_than:30d invoice"
      }
    }
  ]
}
  • from: / to:

    送信者 / 受信者(toまたはcc)、名前やアドレスの一部。

  • subject: / label:

    件名のテキスト / ラベル。

  • in:

    inbox、sent、archive、trash、spam、drafts、promotions、snoozed、scheduled、agents、not-subscribing、またはカスタムフォルダーのid。

  • has:attachment

    添付ファイルのあるメッセージのみ。

  • is:unread / is:read / is:starred / is:important

    メッセージの状態。

  • after: / before:

    日付YYYY/MM/DD(またはYYYY-MM-DD)、UTC。

  • newer_than: / older_than:

    7d、2w、3m(30日)、1y。

検索語のない絞り込みのみ(is:unread in:archive)の場合は、messagesではなくthreads(そのフォルダーの会話一覧)を返します。

検索の例

リクエストボディ

// subject + body + sender name
{
  "commands": [
    {
      "command": "search",
      "args": {
        "query": "invoice september"
      }
    }
  ]
}

// exact sender
{
  "commands": [
    {
      "command": "search",
      "args": {
        "query": "ana@client.com",
        "field": "from"
      }
    }
  ]
}

// everyone from a domain
{
  "commands": [
    {
      "command": "search",
      "args": {
        "query": "client.com"
      }
    }
  ]
}

// messages with a label
{
  "commands": [
    {
      "command": "search",
      "args": {
        "query": "cliente-vip",
        "field": "label"
      }
    }
  ]
}

エラー

HTTPレベルのエラーはtype、code、messageを返します。CMDと表示されたエラーは、HTTP 200でコマンドの結果内に返ります。

  • 401TOKEN_EXPIRED

    access tokenの有効期限が切れました。Refresh Tokenを呼んでリクエストを繰り返してください。

  • 401INVALID_TOKEN

    トークンの形式が不正、不明、または取り消されています。

  • 429RATE_LIMITED

    同じIP + メールボックスで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。

  • CMDINVALID_ARGS

    必須の引数がないか不正です。

  • CMDINVALID_CURSOR

    カーソルが不正か、別のアカウントまたはフォルダーのものです。

  • CMDINTERNAL

    サーバーエラー。詳細はサーバーのログにのみ記録されます。