# 发送第一封邮件

> 创建发信密钥并调用 POST /emails。邮件进入队列后，API 会返回邮件 ID。

每封电子邮件都以一个 `POST /emails` 请求开始,Sendtern 验证它,返回 `200 OK` 及其 ID,并在后台传递。

## 请求的解剖学

cURL:

```
curl -X POST 'https://sendtern.com/emails' \
  -H 'Authorization: Bearer st_your_api_key' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@mail.example.com>",
  "to": [
    "ada@example.com"
  ],
  "reply_to": "support@example.com",
  "subject": "Your sign-in code",
  "html": "<p>Your code is <strong>482 913</strong></p>",
  "text": "Your code is 482 913",
  "tags": [
    {
      "name": "category",
      "value": "auth"
    }
  ]
}'
```

Node.js:

```
const res = await fetch("https://sendtern.com/emails", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SENDTERN_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "from": "Acme <hello@mail.example.com>",
    "to": [
      "ada@example.com"
    ],
    "reply_to": "support@example.com",
    "subject": "Your sign-in code",
    "html": "<p>Your code is <strong>482 913</strong></p>",
    "text": "Your code is 482 913",
    "tags": [
      {
        "name": "category",
        "value": "auth"
      }
    ]
  }),
});

const data = await res.json();
```

Python:

```
import os
import requests

res = requests.post(
    "https://sendtern.com/emails",
    headers={"Authorization": f"Bearer {os.environ['SENDTERN_API_KEY']}"},
    json={
      "from": "Acme <hello@mail.example.com>",
      "to": [
        "ada@example.com"
      ],
      "reply_to": "support@example.com",
      "subject": "Your sign-in code",
      "html": "<p>Your code is <strong>482 913</strong></p>",
      "text": "Your code is 482 913",
      "tags": [
        {
          "name": "category",
          "value": "auth"
        }
      ]
    },
)

print(res.json())
```

## 发送者

`from`接受裸地址或`Name <address>`。 [发送前请确认发件人域名](https://sendtern.com/docs/domains ) 。

## 受益人

- `to` 采用字符串或数组,每个电子邮件最多可包含 50 个地址。
- `cc` 和 `bcc` 的工作方式相同,并向 50 计数。
- `reply_to` 设置回复的发送位置,例如您的支持收件箱。

## 内容

森德 `html`, `text`HTML 文件最多可以有 200,000 个字符,纯文本文件最多可以有 100,000 个字符。

## 标签

发送最多 10 个 `tags`。每个标签都有一个 `name` 和一个 `value`,每个标签最多可包含 128 个字母、数字、连字符或下划线。

## 请求后

电子邮件开始为 **queued ** ,并在收件人的服务器响应时通过 [statuses](https://sendtern.com/docs/statuses) 移动。使用返回的 `id` 随时 [检索它](https://sendtern.com/docs/api-get-email ) 。
