メールの受信:添付ファイル

Get Attachment

メッセージの添付ファイルを、コマンドの結果内でbase64としてダウンロードします。

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

get_messages(attachmentsを含める)のattachment_idを使います。大きなファイルは、Raw Messageでバイナリを直接ダウンロードできます。

セキュリティスキャンでブロックされた添付ファイルは返されません。

引数

  • idstring必須

    message_uid。

  • attachment_idstring必須

    添付ファイルのid。

クイックスタート

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "get_attachment",
        args: {
          id: "Vj0xQUJDMTIz",
          attachment_id: "6f1c2a9e-4b7d-4e21-9a3f-0c8d5e7b1a42"
        }
      }
    ]
  },
  { 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": "get_attachment",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "attachment_id": "6f1c2a9e-4b7d-4e21-9a3f-0c8d5e7b1a42",
        "file_name": "invoice.pdf",
        "content_type": "application/pdf",
        "size_bytes": 48213,
        "content": "JVBERi0xLjcKJcfsj6IK…",
        "inline": false
      }
    }
  ]
}

レスポンスの項目

  • content

    base64のファイル。

  • inline

    本文に埋め込まれた画像(cid)ではtrue。

エラー

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

  • 401TOKEN_EXPIRED

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

  • 401INVALID_TOKEN

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

  • 429RATE_LIMITED

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

  • CMDINVALID_ARGS

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

  • CMDNOT_FOUND

    このトークンでは、そのメッセージ、スレッド、フォルダーは存在しません。

  • CMDFILE_BLOCKED

    ファイルがセキュリティスキャンでブロックされました。

  • CMDINTERNAL

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