Email Service では、Workers binding、REST API、または SMTP を使い、複数の受信者、CC、BCC、名前付きアドレスなど、いくつかの方法で受信者を指定できます。to、cc、bcc を合わせたアドレス数は 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.txtconst 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!"
}'From と To ヘッダーでは 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 API —
send()の完全なリファレンスです。 - REST API — HTTPS で送信します。
- SMTP — SMTP 対応の任意のクライアントから送信します。
- メールの添付ファイル — PDF、インライン画像、アップロードを送信します。