# メールを送信

> トランザクションメールを配信のためにキューに入れます。

`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.

## 体のパラメータ

- `from` (string, required): 送信者アドレス。友好的な名前には `Name <address>` を使ってください。ドメインは確認してください。
- `to` (string | string[], required): 受信者アドレスまたは最大50個の配列。
- `subject` (string, required): メールの件名は 500文字まで
- `html` (string): HTML ボディ。`text` が設定されていない場合は必要です。
- `text` (string): 単純テキストのボディ。テキスト、HTML、または公開されたテンプレートを指定します。
- `cc` (string | string[]): 複写受信者受信者数を 50 にするまで数えてください。
- `bcc` (string | string[]): BCC 受信者受信者数を 50 にするまで数えてください。
- `reply_to` (string | string[]): 答えがどこに行くか
- `tags` (object[]): 10個までのオブジェクトを名前と値で指定できます。
- `template` (object): テンプレートIDまたはエイリアスとオプション変数。

## ヘッダ

- `Idempotency-Key` (string): 最大256文字まで。 [同一性キー](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"
}
```
