cURL
Invia la tua prima email usando solo curl: esporta una chiave API, invia un messaggio con POST e recuperalo con GET per seguirne la consegna. Questo è il flusso HTTP diretto; tutto ciò che fanno gli SDK parte da qui.
1. Esporta la tua chiave API
Crea una chiave nella dashboard sotto Developers > API keys (Invia la tua prima email spiega come fare), poi esportala:
Esempio di codice
export BIRD_API_KEY="bk_us1_..."Il prefisso della regione seleziona il tuo host API: le chiavi bk_us1_ chiamano https://us1.platform.bird.com e le chiavi bk_eu1_ chiamano https://eu1.platform.bird.com. Gli esempi di invio usano us1; cambia l'host se la tua chiave ha un'altra regione.
2. Invia un'email
Invia una POST a /v1/email/messages, usando il dominio condiviso di onboarding come mittente verso l'indirizzo sandbox delivered@messagebird.dev. Non servono verifica del dominio né una casella di posta reale. Seleziona il tab cURL per questa guida rapida.
const msg = await bird.email.send({
from: { email: "onboarding@messagebird.dev", name: "Bird" },
to: ["delivered@messagebird.dev"],
subject: "Hello from Bird",
html: "<p>My first Bird email.</p>",
});
console.log(msg.id, msg.status); // "em_…", "accepted"msg = client.email.send(
from_={"email": "onboarding@messagebird.dev", "name": "Bird"},
to=["delivered@messagebird.dev"],
subject="Hello from Bird",
html="<p>My first Bird email.</p>",
)
print(msg.id, msg.status)package main
import (
"context"
"fmt"
"log"
"os"
bird "github.com/messagebird/bird-sdk-go"
"github.com/messagebird/bird-sdk-go/option"
)
func main() {
client, err := bird.NewClient(option.WithAPIKey(os.Getenv("BIRD_API_KEY")))
if err != nil {
log.Fatal(err)
}
msg, err := client.Email.Send(context.Background(), bird.EmailSendParams{
From: "onboarding@messagebird.dev",
To: []string{"delivered@messagebird.dev"},
Subject: "Hello from Bird",
HTML: "<p>My first Bird email.</p>",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(msg.Id, *msg.Status)
}$message = $bird->email->send(
from: 'Bird <onboarding@messagebird.dev>',
to: ['delivered@messagebird.dev'],
subject: 'Hello from Bird',
html: '<p>My first Bird email.</p>',
);
echo $message->getId(), ' ', $message->getStatus();bird email send \
--category transactional \
--cc manager@acme.com \
--from 'Acme Support <noreply@acme.com>' \
--header X-Campaign=spring-2026 \
--html '<h1>Hi there 👋</h1>' \
--metadata '{"user_id":"usr_12345"}' \
--reply-to support@acme.com \
--subject 'Welcome aboard' \
--tag category=welcome \
--text 'Hi there' \
--to 'Jane Doe <delivered@messagebird.dev>' \
--track-clicks=falsecurl -X POST https://us1.platform.bird.com/v1/email/messages \
-H "Authorization: Bearer $BIRD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "onboarding@messagebird.dev",
"to": ["delivered@messagebird.dev"],
"subject": "Hello from Bird",
"html": "<p>My first Bird email.</p>"
}'API risponde con 202: Bird ha accettato l'email e la consegna in modo asincrono. I campi *_count tracciano i destinatari attraverso gli stati di consegna. Nella risposta iniziale, un destinatario è accettato e nessuno è consegnato:
Esempio di codice
{
"id": "em_01ky7ma8y2es1s2akzk53tmjn0",
"status": "accepted",
"category": "marketing",
"from": { "email": "onboarding@messagebird.dev" },
"to": [{ "email": "delivered@messagebird.dev" }],
"subject": "Hello from Bird",
"accepted_count": 1,
"processed_count": 0,
"delivered_count": 0,
"deferred_count": 0,
"bounced_count": 0,
"complained_count": 0,
"rejected_count": 0,
"open_count": 0,
"click_count": 0,
"track_opens": true,
"track_clicks": true,
"created_at": "2026-07-23T13:58:20.866Z"
}HTTP raw non ha un SDK che genera una chiave di idempotenza al posto tuo. Per protezione in caso di nuovo tentativo, fornisci una chiave al primo invio e riutilizzala quando riprovi. Consulta Idempotenza per un esempio e i limiti di replay.
3. Segui la consegna
Recupera il messaggio con una GET usando il suo ID em_ e osserva lo stato passare da accepted a processed fino a delivered. Seleziona di nuovo il tab cURL:
const msg = await bird.email.get("em_abc123");
msg.status; // "accepted" | "processed" | "delivered" | "bounced" | …
msg.delivered_count;
msg.bounced_count;message = client.email.get("em_abc123")
print(message.id, message.status, message.delivered_count)package main
import (
"context"
"fmt"
"log"
"os"
bird "github.com/messagebird/bird-sdk-go"
"github.com/messagebird/bird-sdk-go/option"
)
func main() {
client, err := bird.NewClient(option.WithAPIKey(os.Getenv("BIRD_API_KEY")))
if err != nil {
log.Fatal(err)
}
msg, err := client.Email.Get(context.Background(), "em_abc123")
if err != nil {
log.Fatal(err)
}
fmt.Println(*msg.Status, *msg.DeliveredCount)
}$message = $bird->email->get('em_01krdgeqcxet5s7t44vh8rt9mg');
echo $message->getStatus();bird email get <message-id>curl https://us1.platform.bird.com/v1/email/messages/em_01ky7ma8y2es1s2akzk53tmjn0 \
-H "Authorization: Bearer $BIRD_API_KEY"Poiché il destinatario è l'indirizzo sandbox delivered@messagebird.dev, la consegna è garantita: il messaggio attraversa la pipeline reale di Bird ma non raggiunge mai una casella di posta reale.
Passi successivi
- Riferimento API email: lo schema completo di richiesta e risposta.
- Autenticazione: chiavi, scope e l'header Authorization.
- Invia la tua prima email: lo stesso flusso con la dashboard e gli SDK.
- Domini di invio: verifica il tuo dominio per l'invio in produzione.
Risorse correlate
Prosegui con la documentazione, le guide e gli esempi per questo argomento. Le risorse sono in inglese.
Guarda la guidaGetting started with emailComprendi il concettoShould I use a Bird SDK or call the API directly?Esplora la funzionalitàEmailSegui il percorso di apprendimentoBuild your first integration
Prova l'esercitazione e ottieni un brief di implementazione