跳转到内容
搜索文档

指定收件人

使用 Workers 绑定、REST API 或 SMTP 发送至多个收件人、抄送和密送,以及带显示名称的地址。

最后更新 查看 MarkdownAgent 设置

Email Service 支持以多种方式指定收件人——多个收件人、抄送(CC)和密送(BCC),以及带显示名称的地址——可使用 Workers 绑定REST APISMTPtoccbcc 中的地址总数不得超过 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 标志。

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

抄送与密送

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 标头。密送收件人通过 --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

后续步骤

这篇文档对您有帮助吗?