# 寄出第一封郵件

> 建立寄件金鑰後呼叫 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` 隨時可以 [retrieve it](https://sendtern.com/docs/api-get-email ) 。
