# Gửi thư

> Đang xếp hàng để nhận email giao dịch.

`POST /emails`

Accepts the email and returns HTTP 200 with its ID. Delivery happens asynchronously; follow it with [Retrieve email](https://sendtern.com/docs/api-get-email). Send an `Idempotency-Key` header to retry safely.

## Tập tin

- `from` (string, required): Địa chỉ người gửi. Dùng `Name <address>` cho tên thân thiện. Miền phải được xác thực.
- `to` (string | string[], required): Địa chỉ người nhận, hoặc một dãy lên đến 50.
- `subject` (string, required): Tiêu đề email, tối đa 500 ký tự.
- `html` (string): Thân HTML. Cần thiết trừ khi đã đặt `text`.
- `text` (string): Cơ thể văn bản đơn giản. Cho văn bản, HTML, hoặc mẫu đã xuất bản.
- `cc` (string | string[]): Người nhận copy, đếm đến giới hạn 50 người nhận.
- `bcc` (string | string[]): Người nhận BCC, đếm đến giới hạn 50 người nhận.
- `reply_to` (string | string[]): Đâu là nơi trả lời.
- `tags` (object[]): Tối đa mười đối tượng chứa tên và giá trị.
- `template` (object): Một ID mẫu hoặc biệt danh đã xuất bản và các biến tùy chọn.

## Tiêu đề

- `Idempotency-Key` (string): Tối đa 256 ký tự. Xem [Khóa đồng nghĩa](https://sendtern.com/docs/idempotency).

## Example

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.acme.io>",
  "to": [
    "ada@example.com"
  ],
  "subject": "Your sign-in code",
  "html": "<p>482 913</p>",
  "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.acme.io>",
    "to": [
      "ada@example.com"
    ],
    "subject": "Your sign-in code",
    "html": "<p>482 913</p>",
    "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.acme.io>",
      "to": [
        "ada@example.com"
      ],
      "subject": "Your sign-in code",
      "html": "<p>482 913</p>",
      "tags": [
        {
          "name": "category",
          "value": "auth"
        }
      ]
    },
)

print(res.json())
```

## Response

```json
{
  "id": "47be30ca-24b7-48fb-b35d-ff287b89e66d"
}
```
