INTEGRITY Cloudflare Docs

Specify recipients

Email Service lets you specify recipients in several ways — multiple recipients, CC and BCC, and named addresses — using the Workers binding, the REST API, or SMTP. The combined number of addresses across to, cc, and bcc must not exceed 50. See Limits.

Multiple recipients

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"
  }'

List every recipient in the To header and pass one --mail-rcpt flag per address.

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 and 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"
  }'

Add a Cc header for CC recipients. BCC recipients are added as --mail-rcpt flags but omitted from the headers.

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

Named recipients

Provide a display name alongside the address for the sender and recipients.

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!"
  }'

Use the Display Name <address> form in the From and To headers.

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

Mixed plain and named recipients

Combine plain addresses and named addresses in the same to field.

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

Next steps