Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

REST API

最終更新 Markdown で表示Agent セットアップ

REST API では、POST /accounts/{account_id}/email/sending/send への標準的な HTTP リクエストで、任意のアプリケーションからメールを送信できます。バックエンド、サーバーレス関数、CI/CD パイプラインなど、どこからでも使えます。Cloudflare Workers のバインディングは不要です。

OpenAPI 仕様の全体は、Email Sending API リファレンス を参照してください。

Cloudflare は REST API 向けの公式 SDK も提供しています。NodePythonGo です。

認証

メール送信の権限がある Cloudflare API トークン で認証します。Authorization ヘッダーに含めます。

Authorization: Bearer <API_TOKEN>

メールを送信する

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
  --header "Authorization: Bearer <API_TOKEN>" \
  --header "Content-Type: application/json" \
  --data '{
    "to": "[email protected]",
    "from": "[email protected]",
    "subject": "Welcome to our service!",
    "html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
    "text": "Welcome! Thanks for signing up."
  }'

複数の宛先、CC / BCC、名前付きアドレスについては、宛先の指定 を参照してください。

添付ファイル

attachments 配列に Base64 エンコードした内容を入れて、ファイルを送信します。メッセージ全体のサイズは、添付ファイルを含めて 5 MiB 以下である必要があります。

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
  --header "Authorization: Bearer <API_TOKEN>" \
  --header "Content-Type: application/json" \
  --data '{
    "to": "[email protected]",
    "from": "[email protected]",
    "subject": "Your Invoice",
    "html": "<h1>Invoice attached</h1><p>Please find your invoice attached.</p>",
    "attachments": [
      {
        "content": "JVBERi0xLjQKJeLjz9MK...",
        "filename": "invoice-12345.pdf",
        "type": "application/pdf",
        "disposition": "attachment"
      }
    ]
  }'

インライン画像とファイルアップロードについては、メールの添付ファイル を参照してください。

カスタムヘッダー

スレッド化、リスト管理、トラッキング用のカスタムヘッダーを設定できます。許可されているヘッダーの一覧は、メールヘッダーのリファレンス を参照してください。

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
  --header "Authorization: Bearer <API_TOKEN>" \
  --header "Content-Type: application/json" \
  --data '{
    "to": "[email protected]",
    "from": "[email protected]",
    "subject": "Your weekly digest",
    "html": "<h1>Weekly Digest</h1>",
    "headers": {
      "List-Unsubscribe": "<https://yourdomain.com/unsubscribe?id=abc123>",
      "List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
      "X-Campaign-ID": "weekly-digest-2026-03"
    }
  }'

レスポンス

成功時のレスポンスでは、宛先ごとの配信ステータスが返ります。

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": {
		"delivered": ["[email protected]"],
		"permanent_bounces": [],
		"queued": []
	}
}
  • delivered - メッセージがすぐに配信されたメールアドレス
  • permanent_bounces - 永続的にバウンスしたメールアドレス
  • queued - あとで配信するためにキューに入ったメールアドレス

エラー処理

REST API は、標準の Cloudflare API エラーレスポンスを返します。失敗したリクエストでは、数値のエラーコードと機械可読なメッセージを含む errors 配列が返ります。

{
	"success": false,
	"errors": [
		{
			"code": 10001,
			"message": "email.sending.error.invalid_request_schema"
		}
	],
	"messages": [],
	"result": null
}

REST API のエラーコード:

HTTP Status Code Message 説明
400 10001 email.sending.error.invalid_request_schema リクエスト形式が不正です
400 10200 email.sending.error.email.too_big メールがサイズ上限を超えています
400 10201 email.sending.error.email.no_content_length Content-Length がありません
400 10202 email.sending.error.email.invalid メールの内容が不正です
401 10101 email.sending.error.authentication.unauthorized API トークンがないか、無効です
401 10103 email.sending.error.authentication.bad_token_type このエンドポイントに対するトークンの種類が違います
403 10102 email.sending.error.authentication.forbidden トークンに送信権限がありません
403 10105 email.sending.error.authentication.not_entitled アカウントに Email Sending の利用権限がありません
403 10203 email.sending.error.email.sending_disabled このゾーンまたはアカウントでは送信が無効です
404 10000 email.sending.error.not_found リソースが見つかりません
429 10004 email.sending.error.throttled レート制限を超えました
500 10002 email.sending.error.internal_server 内部サーバーエラー
500 10003 email.sending.error.not_implemented この操作は実装されていません
503 10100 email.sending.error.authentication.upstream 認証サービスが一時的に利用できません

次のステップ

  • リクエストとレスポンスのスキーマ全体は、Email Sending API リファレンス を参照してください。
  • バインディングを使って Cloudflare Workers から直接メールを送る場合は、Workers API を参照してください。
  • SMTP 対応のアプリケーションやメールクライアントから送る場合は、SMTP を参照してください。
  • スレッド化、リスト管理、カスタムトラッキングヘッダーについては、メールヘッダー を確認してください。

役に立ちましたか?