# 购买发信域名

Source: https://won.dev/zh/docs/email/domains-create

`POST https://api.won.dev/v1/email/domains`

为一个发件方购买发信域名：每个域名带 3 个已预热的邮箱，只为这个发件方发信，让它每天多发 45 封。无需任何配置：不用设置 DNS，不用登录邮箱，回信也由我们读取。每个域名每天 $0.9，从续费日起每次付 30 天。所有域名都在每月的同一天续费，所以第一个周期从今天到那一天：15 到 45 天，现在支付。每个域名会在 `period_end` 前 3 天自动从余额续费；余额不足时会一直重试到前一天，之后域名会被释放。不带 `confirm: true` 时只报价，并给出续费日期和库存数量，不做任何改动。新域名几分钟内就绪（`domain.ready`），第一天可发 15 封，5 天后达到全速。该发件方因 `no_domains` 暂停的活动会在域名就绪后自动继续。库存不足时返回 `out_of_stock`，不会扣费。单次最多 10 个。测试 key 只会拿到报价：沙箱中每个发件方都已有一个模拟域名。每次带 `confirm: true` 的调用都会再买一次：请带上 `Idempotency-Key`，让重试变得安全。

- **计费：** `email_domain_day` $0.9：一个发信域名使用一天。带 `confirm: true` 时立即按到 `period_end` 的天数扣费，之后在每次续费前 3 天按 30 天扣费。不带时只报价，免费。

用测试 key（`won_test_...`）发送这个请求，会在[沙箱](/zh/docs/email#sandbox)中运行：不发信，不收费。

## 参数 [#parameters]

参数放在 JSON 请求体里。`POST` 请求还支持 `Idempotency-Key` 请求头，见[重复请求](/zh/docs/email#idempotency)。

| 参数 | 类型 | 必填 | 说明（API 原文） |
| --- | --- | --- | --- |
| `sender_id` | string | 是 | The sender to buy them for, such as `snd_4k2m9x7p1q8w3e5r`. They never send for another. |
| `count` | integer | 否 | How many domains, 1 to 10. Default: `1`. |
| `confirm` | boolean | 否 | True buys them and charges this period. False, the default, only quotes it. Default: `false`. |
| `max_cost` | number | 否 | Spending cap for this call in US dollars. If the call could cost more, it fails with `budget_exceeded` before anything is charged. |

## 响应 [#response]

错误说明见[错误码](/zh/docs/errors)。

| 字段 | 类型 | 说明（API 原文） |
| --- | --- | --- |
| `data` | object | The domains and their price. |
| `data.confirmed` | boolean | True when the domains were bought. False on a quote: nothing changed. |
| `data.sender_id` | string |  |
| `data.count` | integer | How many domains. |
| `data.price` | number | What they cost now, together, in US dollars: this period, up to `period_end`. |
| `data.price_per_domain` | number | What one costs for this period, in US dollars. |
| `data.days` | integer | Days this period has, today included. |
| `data.period_end` | string | When this period ends and they renew, at `price_per_month` each, charged from your balance 3 days before. |
| `data.price_per_month` | number | What one domain costs for 30 days, from then on. |
| `data.daily_limit` | integer | What they add to the sender's day at full speed: 45 each. |
| `data.first_day_limit` | integer | What they send on their first day, together. |
| `data.days_to_full_speed` | integer | Days until they send at full speed. |
| `data.in_stock` | integer | How many domains can be bought right now. |
| `data.domains` | object[] | The domains bought, `setting_up` for a few minutes. Empty on a quote. |
| `data.domains[].id` | string | Domain ID, such as `dom_5r4k2m9x7p1q8w3e`. |
| `data.domains[].sender_id` | string | The sender it sends for. It never sends for another. |
| `data.domains[].domain` | string \| null | The domain name. Null for the minutes after it was paid for, until one is chosen and bought. |
| `data.domains[].status` | `setting_up` \| `ramping` \| `active` \| `paused` \| `ending` \| `released` \| `failed` | `setting_up` for the minutes it takes to buy it and set up its mailboxes. `ramping` while it sends a few emails a day more each day, for 5 days. `active` at full speed. `paused` while we hold it back. `ending` once it will not renew: it sends until 1 day before `period_end`. Final: `released` (its mailboxes are gone) and `failed` (it could not be bought; what it cost went back to the balance). |
| `data.domains[].end_reason` | `canceled` \| `unpaid` \| `replaced` \| `removed` \| null | Why it ends or ended: `canceled` by you, `unpaid` (the renewal could not be charged), `replaced` by a new domain, `removed` by us. Null while it renews. |
| `data.domains[].mailboxes` | object[] | Its mailboxes, 3 as a rule. Empty while it is set up. Replies to them are read for you: you never sign in to them. |
| `data.domains[].mailboxes[].address` | string | The address emails go out from, and replies come back to. |
| `data.domains[].mailboxes[].name` | string | The name it sends under, the one it was warmed up with. |
| `data.domains[].daily_limit` | integer | What its mailboxes may send today, together. |
| `data.domains[].full_daily_limit` | integer | What they send a day at full speed, together: 45. |
| `data.domains[].sent_today` | integer | Emails they sent since midnight UTC. Answers to replies are left out. |
| `data.domains[].full_speed_at` | string \| null | When it reaches full speed, while it is `ramping`. Null otherwise. |
| `data.domains[].price_per_month` | number | What a renewal costs, for 30 days, in US dollars. |
| `data.domains[].period_end` | string | When the paid period ends. The next one is charged from your balance a few days before, as an ISO 8601 time in UTC. |
| `data.domains[].renews` | boolean | Whether it renews at `period_end`. False once you canceled it. |
| `data.domains[].ends_at` | string \| null | When it stops sending and its mailboxes are given up, when it will not renew. Null while it renews. |
| `data.domains[].renewal_failed_at` | string \| null | When charging the renewal last failed for want of balance. It is tried again until the day before `period_end`, then the domain is given up. Null when nothing failed. |
| `data.domains[].stats` | object | The last 30 days. |
| `data.domains[].stats.sent` | integer | Emails sent. |
| `data.domains[].stats.bounced` | integer | Of them, how many bounced because the mailbox does not exist. |
| `data.domains[].stats.bounce_rate` | number | `bounced` over `sent`, 0 to 1. |
| `data.domains[].stats.complaints` | integer | Recipients who reported its emails as spam. |
| `data.domains[].test` | boolean | The simulated domain of a test key's sender: it never sends for real. |
| `data.domains[].created_at` | string | When it was bought, as an ISO 8601 time in UTC. |
| `data.domains[].ready_at` | string \| null | When its mailboxes could send. |
| `data.domains[].ended_at` | string \| null | When it was released, or failed. |
| `notice` | string \| null | A plain sentence when there is something to know about this answer. Null otherwise. |
| `usage` | object | What this call was charged, and the balance left. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.breakdown` | object[] | Every billing unit that came back, charged or not. Empty when nothing did. |
| `usage.breakdown[].unit` | `email_domain_day` | What is counted. |
| `usage.breakdown[].records` | integer | How many were returned and charged. |
| `usage.breakdown[].already_paid` | integer | How many more were returned for free, because this organization paid for them in the last 30 days. |
| `usage.breakdown[].cost` | number | What they cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

## 示例 [#example]

```bash
curl https://api.won.dev/v1/email/domains \
  -H "Authorization: Bearer $WON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "sender_id": "snd_4k2m9x7p1q8w3e5r",
  "count": 1,
  "confirm": true,
  "max_cost": 30
}'
```

```json
{
  "data": {
    "confirmed": true,
    "sender_id": "snd_4k2m9x7p1q8w3e5r",
    "count": 1,
    "price": 28.8,
    "price_per_domain": 28.8,
    "days": 32,
    "period_end": "2026-12-28T00:00:00.000Z",
    "price_per_month": 27,
    "daily_limit": 45,
    "first_day_limit": 15,
    "days_to_full_speed": 5,
    "in_stock": 24,
    "domains": [
      {
        "id": "dom_5r4k2m9x7p1q8w3e",
        "sender_id": "snd_4k2m9x7p1q8w3e5r",
        "domain": null,
        "status": "setting_up",
        "end_reason": null,
        "mailboxes": [],
        "daily_limit": 0,
        "full_daily_limit": 45,
        "sent_today": 0,
        "full_speed_at": null,
        "price_per_month": 27,
        "period_end": "2026-12-28T00:00:00.000Z",
        "renews": true,
        "ends_at": null,
        "renewal_failed_at": null,
        "stats": {
          "sent": 0,
          "bounced": 0,
          "bounce_rate": 0,
          "complaints": 0
        },
        "test": false,
        "created_at": "2026-11-26T10:15:02.000Z",
        "ready_at": null,
        "ended_at": null
      }
    ]
  },
  "notice": null,
  "usage": {
    "cost": 28.8,
    "breakdown": [
      {
        "unit": "email_domain_day",
        "records": 32,
        "already_paid": 0,
        "cost": 28.8
      }
    ],
    "balance": 19.28,
    "replayed": false
  }
}
```