Email Service では、Workers binding、REST API、または SMTP を使い、複数の受信者、CC、BCC、名前付きアドレスなど、いくつかの方法で受信者を指定できます。to、cc、bcc を合わせたアドレス数は 50 を超えてはなりません。制限 を参照してください。
const response = await env.EMAIL.send({
to: ["user1@example.com", "user2@example.com", "user3@example.com"],
from: { email: "newsletter@yourdomain.com", 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": ["user1@example.com", "user2@example.com"],
"from": { "address": "newsletter@yourdomain.com", "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 <newsletter@yourdomain.com>
To: user1@example.com, user2@example.com
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 "newsletter@yourdomain.com" \
--mail-rcpt "user1@example.com" \
--mail-rcpt "user2@example.com" \
--upload-file mail.txtconst response = await env.EMAIL.send({
to: "customer@example.com",
cc: ["manager@example.com"],
bcc: ["archive@example.com"],
from: "orders@yourdomain.com",
replyTo: "support@yourdomain.com",
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": "customer@example.com",
"cc": ["manager@example.com"],
"bcc": ["archive@example.com"],
"from": "orders@yourdomain.com",
"reply_to": "support@yourdomain.com",
"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: orders@yourdomain.com
To: customer@example.com
Cc: manager@example.com
Reply-To: support@yourdomain.com
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 "orders@yourdomain.com" \
--mail-rcpt "customer@example.com" \
--mail-rcpt "manager@example.com" \
--mail-rcpt "archive@example.com" \
--upload-file mail.txt送信者と受信者について、アドレスに加えて表示名を指定します。
const response = await env.EMAIL.send({
to: { email: "jane@example.com", name: "Jane Doe" },
from: { email: "support@yourdomain.com", 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": "jane@example.com", "name": "Jane Doe" },
"from": { "address": "support@yourdomain.com", "name": "Support Team" },
"subject": "Welcome!",
"html": "<h1>Thanks for joining!</h1>",
"text": "Thanks for joining!"
}'From と To ヘッダーでは Display Name <address> の形式を使います。
cat > mail.txt <<EOF
From: Support Team <support@yourdomain.com>
To: Jane Doe <jane@example.com>
Subject: Welcome!
Thanks for joining!
EOF
curl --ssl-reqd \
--url "smtps://smtp.mx.cloudflare.net:465" \
--user "api_token:<API_TOKEN>" \
--mail-from "support@yourdomain.com" \
--mail-rcpt "jane@example.com" \
--upload-file mail.txt同じ to フィールドで、プレーンなアドレスと名前付きアドレスを組み合わせます。
const response = await env.EMAIL.send({
to: ["plain@example.com", { email: "jane@example.com", name: "Jane Doe" }],
from: "support@yourdomain.com",
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": [
"plain@example.com",
{ "address": "jane@example.com", "name": "Jane Doe" }
],
"from": "support@yourdomain.com",
"subject": "Team update",
"html": "<h1>Monthly update</h1>",
"text": "Monthly update"
}'cat > mail.txt <<EOF
From: support@yourdomain.com
To: plain@example.com, Jane Doe <jane@example.com>
Subject: Team update
Monthly update
EOF
curl --ssl-reqd \
--url "smtps://smtp.mx.cloudflare.net:465" \
--user "api_token:<API_TOKEN>" \
--mail-from "support@yourdomain.com" \
--mail-rcpt "plain@example.com" \
--mail-rcpt "jane@example.com" \
--upload-file mail.txt- Workers API —
send()の完全なリファレンスです。 - REST API — HTTPS で送信します。
- SMTP — SMTP 対応の任意のクライアントから送信します。
- メールの添付ファイル — PDF、インライン画像、アップロードを送信します。