Go · Gin
Send your first email from a Gin application in three steps: install the SDK, add a route that sends, and run it.
1. Install
Exemple de code
go get github.com/messagebird/bird-sdk-goThe 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:
Exemple de code
export BIRD_API_KEY="bk_us1_..."2. Send
Create main.go with a route that sends through Bird's shared onboarding domain — no domain verification needed:
Exemple de code
package main
import (
"errors"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
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)
}
r := gin.Default()
r.POST("/send", func(c *gin.Context) {
msg, err := client.Email.Send(c.Request.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) {
c.JSON(apiErr.StatusCode, gin.H{"error": apiErr.Error()})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusAccepted, msg)
})
log.Fatal(r.Run(":3000"))
}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
Exemple de code
go run . &
curl -X POST localhost:3000/sendThe API responds with 202 — Bird has accepted the email and delivers it asynchronously:
Exemple de code
{
"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
- Go SDK reference — every method, param, and error type.
- Send your first email — the same flow with curl and the dashboard.
- Sending domains — verify your own domain for production sending.
- Email API reference — the full request and response schema.