Skip to content

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

受信者を指定する

Email Service で送信するときに、複数の受信者、CC、BCC、名前付きアドレスを指定します。

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

Email Service では、Workers bindingREST API、または SMTP を使い、複数の受信者、CC、BCC、名前付きアドレスなど、いくつかの方法で受信者を指定できます。toccbcc を合わせたアドレス数は 50 を超えてはなりません。制限 を参照してください。

複数の受信者

const response = await env.EMAIL.send({
	to: ["[email protected]", "[email protected]", "[email protected]"],
	from: { email: "[email protected]", name: "Newsletter Team" },
	subject: "Monthly Newsletter",
	html: "<h1>This month's updates</h1>",
	text: "This month's updates",
});
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]", "[email protected]"],
    "from": { "address": "[email protected]", "name": "Newsletter Team" },
    "subject": "Monthly Newsletter",
    "html": "<h1>This month'\''s updates</h1>",
    "text": "This month'\''s updates"
  }'

すべての受信者を To ヘッダーに列挙し、アドレスごとに --mail-rcpt フラグを 1 つ渡します。

cat > mail.txt <<EOF
From: Newsletter Team <[email protected]>
To: [email protected], [email protected]
Subject: Monthly Newsletter

This month's updates
EOF

curl --ssl-reqd \
  --url "smtps://smtp.mx.cloudflare.net:465" \
  --user "api_token:<API_TOKEN>" \
  --mail-from "[email protected]" \
  --mail-rcpt "[email protected]" \
  --mail-rcpt "[email protected]" \
  --upload-file mail.txt

CC と BCC

const response = await env.EMAIL.send({
	to: "[email protected]",
	cc: ["[email protected]"],
	bcc: ["[email protected]"],
	from: "[email protected]",
	replyTo: "[email protected]",
	subject: "Order Confirmation #12345",
	html: "<h1>Your order is confirmed</h1>",
	text: "Your order is confirmed",
});
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]",
    "cc": ["[email protected]"],
    "bcc": ["[email protected]"],
    "from": "[email protected]",
    "reply_to": "[email protected]",
    "subject": "Order Confirmation #12345",
    "html": "<h1>Your order is confirmed</h1>",
    "text": "Your order is confirmed"
  }'

CC の受信者には Cc ヘッダーを追加します。BCC の受信者は --mail-rcpt フラグで追加し、ヘッダーには含めません。

cat > mail.txt <<EOF
From: [email protected]
To: [email protected]
Cc: [email protected]
Reply-To: [email protected]
Subject: Order Confirmation #12345

Your order is confirmed
EOF

curl --ssl-reqd \
  --url "smtps://smtp.mx.cloudflare.net:465" \
  --user "api_token:<API_TOKEN>" \
  --mail-from "[email protected]" \
  --mail-rcpt "[email protected]" \
  --mail-rcpt "[email protected]" \
  --mail-rcpt "[email protected]" \
  --upload-file mail.txt

名前付き受信者

送信者と受信者について、アドレスに加えて表示名を指定します。

const response = await env.EMAIL.send({
	to: { email: "[email protected]", name: "Jane Doe" },
	from: { email: "[email protected]", name: "Support Team" },
	subject: "Welcome!",
	html: "<h1>Thanks for joining!</h1>",
	text: "Thanks for joining!",
});
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": { "address": "[email protected]", "name": "Jane Doe" },
    "from": { "address": "[email protected]", "name": "Support Team" },
    "subject": "Welcome!",
    "html": "<h1>Thanks for joining!</h1>",
    "text": "Thanks for joining!"
  }'

FromTo ヘッダーでは Display Name <address> の形式を使います。

cat > mail.txt <<EOF
From: Support Team <[email protected]>
To: Jane Doe <[email protected]>
Subject: Welcome!

Thanks for joining!
EOF

curl --ssl-reqd \
  --url "smtps://smtp.mx.cloudflare.net:465" \
  --user "api_token:<API_TOKEN>" \
  --mail-from "[email protected]" \
  --mail-rcpt "[email protected]" \
  --upload-file mail.txt

プレーンと名前付きの混在

同じ to フィールドで、プレーンなアドレスと名前付きアドレスを組み合わせます。

const response = await env.EMAIL.send({
	to: ["[email protected]", { email: "[email protected]", name: "Jane Doe" }],
	from: "[email protected]",
	subject: "Team update",
	html: "<h1>Monthly update</h1>",
	text: "Monthly update",
});
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]",
      { "address": "[email protected]", "name": "Jane Doe" }
    ],
    "from": "[email protected]",
    "subject": "Team update",
    "html": "<h1>Monthly update</h1>",
    "text": "Monthly update"
  }'
cat > mail.txt <<EOF
From: [email protected]
To: [email protected], Jane Doe <[email protected]>
Subject: Team update

Monthly update
EOF

curl --ssl-reqd \
  --url "smtps://smtp.mx.cloudflare.net:465" \
  --user "api_token:<API_TOKEN>" \
  --mail-from "[email protected]" \
  --mail-rcpt "[email protected]" \
  --mail-rcpt "[email protected]" \
  --upload-file mail.txt

次のステップ

  • Workers APIsend() の完全なリファレンスです。
  • REST API — HTTPS で送信します。
  • SMTP — SMTP 対応の任意のクライアントから送信します。
  • メールの添付ファイル — PDF、インライン画像、アップロードを送信します。

役に立ちましたか?