# Invia la prima email

> Crea una chiave di invio e chiama POST /emails. L’API restituisce un ID quando il messaggio entra in coda.

Ogni email inizia come una richiesta `POST /emails`, Sendtern la convalida, restituisce `200 OK` con il suo ID e consegna in background.

## Anatomia di una richiesta

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())
```

## Mittente

`from` accetta un indirizzo nudo o `Name <address>`. [Verificare il dominio esatto del mittente](https://sendtern.com/docs/domains) prima di inviare.

## Destinatari

- `to` prende una stringa o un array, fino a 50 indirizzi per email.
- `cc` e `bcc` funzionano allo stesso modo e contano verso il 50.
- `reply_to` imposta dove vanno le risposte, ad esempio la tua casella di posta del supporto.

## Contenuto

Invia `html`, `text` o entrambi: l'HTML può contenere fino a 200.000 caratteri e il testo normale fino a 100.000 caratteri.

## Tag

Invia fino a 10 `tags`. Ogni tag ha un `name` e un `value`, ciascuno fino a 128 lettere, cifre, trattini o sottolineature.

## Dopo la richiesta

L'email inizia come **coda** e si sposta attraverso gli [status](https://sendtern.com/docs/statuses) mentre il server del destinatario risponde.Usa il `id` restituito per [recuperarlo](https://sendtern.com/docs/api-get-email) in qualsiasi momento.
