Email Service 支持以多种方式指定收件人——多个收件人、抄送(CC)和密送(BCC),以及带显示名称的地址——可使用 Workers 绑定、REST API 或 SMTP。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 标志。
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 标头。密送收件人通过 --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、内联图片和上传文件。