Documentation
Sign inGet started

Go

Send your first email from Go in three steps: install the SDK, write a handler that sends, and run it. This quickstart uses the standard library's net/http — no framework required.

1. Install

Ejemplo de código
go get github.com/messagebird/bird-sdk-go
The SDK requires Go 1.24+. Grab an API key from Developers → API keys in the dashboard and export it — the region is inferred from the key's bk_us1_ / bk_eu1_ prefix, so there's nothing else to configure:
Ejemplo de código
export BIRD_API_KEY="bk_us1_..."

2. Send

Create main.go with an HTTP handler that sends through Bird's shared onboarding domain — no domain verification needed:
Ejemplo de código
package main

import (
	"encoding/json"
	"errors"
	"log"
	"net/http"
	"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)
	}

	http.HandleFunc("POST /send", func(w http.ResponseWriter, r *http.Request) {
		msg, err := client.Email.Send(r.Context(), 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 {
			var apiErr *bird.APIError
			if errors.As(err, &apiErr) {
				http.Error(w, apiErr.Error(), apiErr.StatusCode)
				return
			}
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusAccepted)
		_ = json.NewEncoder(w).Encode(msg)
	})

	log.Fatal(http.ListenAndServe(":3000", nil))
}
Every Send is automatically idempotent: the SDK generates one idempotency key per call and reuses it across retries, so transient failures (timeouts, 429s, 5xx) are retried without ever double-delivering.

3. Try it

Ejemplo de código
go run . &
curl -X POST localhost:3000/send
The API responds with 202 — Bird has accepted the email and delivers it asynchronously:
Ejemplo de código
{
  "id": "em_019c1930687b7bfa8a1b2c3d4e5f6789",
  "status": "accepted"
}
Because the recipient is the delivered@messagebird.dev sandbox address, delivery is guaranteed — fetch the message by its em_ ID with client.Email.Get and watch the status move to delivered.

Next steps