Agents Week 2026 / 發佈時間線 / Cloudflare Email Service

Cloudflare Email Service

Cloudflare Email Service
Developer Docshttps://developers.cloudflare.com/email-service/

Cloudflare Email Service

發送交易電郵,並將收件電郵路由到 Workers 或電郵地址

Cloudflare Email Service 提供強大嘅電郵能力:

注意:向帳戶內已 驗證嘅目的地地址 發送電郵喺所有 plan 上都係免費,即使只設定咗 Email Routing 都一樣。

呢兩個功能夾埋,令你可以由應用程式發送同接收電郵。例如,你可以用 Email Service 做:

你可以直接用 Cloudflare Workers 嘅 bindings、任何平台嘅 REST API,或者 authenticated SMTP 存取 Email Service:

EMAIL binding 發送電郵,並用 src/index.ts 入面嘅 email() handler 處理收件電郵:

interface Env {
  EMAIL: SendEmail;
}

export default {
  // Handle HTTP requests (Email Sending)
  async fetch(request, env, ctx): Promise<Response> {
    // Send a welcome email
    await env.EMAIL.send({
      to: "user@example.com",
      from: "welcome@yourdomain.com",
      subject: "Welcome to our service!",
      html: "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
      text: "Welcome! Thanks for signing up.",
    });
    return new Response("Email sent successfully");
  },

  // Handle incoming emails (Email Routing)
  async email(message, env, ctx): Promise<void> {
    // Forward to support team
    if (message.to.includes("support@yourdomain.com")) {
      await message.forward("team@yourdomain.com");
    }
    // Send auto-reply
    await env.EMAIL.send({
      to: message.from,
      from: "noreply@yourdomain.com",
      subject: "We received your message",
      html: "<h1>Thank you!</h1><p>We'll get back to you soon.</p>",
    });
  },
} satisfies ExportedHandler<Env>;

將 bindings 加入你嘅 Wrangler 設定檔:

{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "<ENTER_WORKER_NAME>",
  "main": "src/index.ts",
  "compatibility_date": "$today",
  // Email sending
  "send_email": [
    { "name": "EMAIL" }
  ],
  // Email routing
  "email": [
    { "name": "EMAIL_HANDLER" }
  ]
}

用 REST API 發送:

curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
  --header "Authorization: Bearer ***" \
  --header "Content-Type: application/json" \
  --data '{
    "to": "user@example.com",
    "from": "welcome@yourdomain.com",
    "subject": "Welcome to our service!",
    "html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
    "text": "Welcome! Thanks for signing up."
  }'

Cloudflare 亦為 REST API 提供官方 SDK:NodePythonGo

或者用 authenticated SMTP:

cat > mail.txt <<EOF
From: welcome@yourdomain.com
To: user@example.com
Subject: Welcome to our service!

Thanks for signing up!
EOF

curl --ssl-reqd \
  --url "smtps://smtp.mx.cloudflare.net:465" \
  --user "api_token:<API_TOKEN>" \
  --mail-from "welcome@yourdomain.com" \
  --mail-rcpt "user@example.com" \
  --upload-file mail.txt

睇完整嘅 API reference 了解 REST API、Workers binding 同 SMTP。

功能

以高送達率同全球性能發送交易電郵。

將收件電郵路由到自訂地址、Workers 或外部目的地。

自動 IP 信譽管理同送達率優化。

用全面嘅指標同警報監察電郵表現。

用 REST API、Workers binding 或 SMTP 發送同路由電郵。