# create()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/mail/create/
Language: zh

`api.mail.create({ address, name }) → Promise<Mailbox>`

创建一个已启用的主机邮箱。 配额来自计划, 而不是来自呼叫者 。

Status: POST /api/mail · host must be enabled · quota from the plan

```javascript
const box = await api.mail.create({ address: "hello@example.com", name: "Hello" });

box.address;   // "hello@example.com"
box.host;      // "example.com"
box.local;     // "hello"
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `address` | string | 必填 | 完整地址。 其主机必须是启用邮件的地址 。 |
| `name` | string |  | 显示名称 。 |

## 必须先启用主机 {#host}

```javascript
import { IaGenifyError } from "iagenify";

try {
  await api.mail.create({ address: "hello@team.example.com" });
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "mail_not_enabled") {
    await domain.mail.enable({ subdomain: "team" });
  }
}
```

拒绝者的名字 缺少主机, 所以,固定是 一次呼叫。

## 打电话者不选择配额 {#quota}

> **是从计划里出来的,是账户的物品存储**
>
> 邮箱没有自己的空间。 配额Bytes是账户的, 每次阅读都是新鲜的, 这就是为什么当主机部署某东西或储存充满时邮箱会更充实。

## 错误 {#errors}

| 代码 | 状态 | 触发条件 |
| --- | --- | --- |
| mail_not_enabled | 403 | 主机还没有邮件记录 。 |
| mail_not_in_plan | 403 | 该计划没有邮件服务。 |
| address_taken | 409 | 地址或别名存在 |
| address_reserved | 400 | 域名要回答 。 |

## 内容如下 {#then}

[(更新)](/zh/sdk/ref/mailbox/update) 图片和签名, [aliases.add()](/zh/sdk/ref/mailbox/aliases/add) 以其他地址 这片土地在这里, [(前)](/zh/sdk/ref/mailbox/forward) 另请注明副本。

- [mail.enable()](/zh/sdk/ref/domain/mail/enable): 在信箱存在之前打开主机 。
- [邮箱邮箱](/zh/sdk/ref/mailbox): 邮箱携带什么,你能做什么
- [usage()](/zh/sdk/ref/mail/usage): 先检查

```python
box = api.mail.create(address="hello@example.com", name="Hello")

box.address   # "hello@example.com"
box.host      # "example.com"
box.local     # "hello"
```

```python
from iagenify import IaGenifyError

try:
    api.mail.create(address="hello@team.example.com")
except IaGenifyError as error:
    if error.code != "mail_not_enabled":
        raise
    domain.mail.enable(subdomain="team")
```
