Go Quickstart

Send your first email from a Go project. Pure Go (no cgo); ships well in scratch containers, Lambda, Cloud Run.

1. Install

terminal
go get github.com/mailstorm/mailstorm-go

2. Get an API key

Generate one at /api-keys. ms_test_* for sandbox, ms_live_* for production (requires verified FROM domain).

3. Send your first email

main.go
package main

import (
    "log"
    "os"

    "github.com/mailstorm/mailstorm-go"
)

func main() {
    ms := mailstorm.New(os.Getenv("MAILSTORM_API_KEY"))

    res, err := ms.Emails.Send(&mailstorm.SendRequest{
        From:    "onboarding@yourdomain.com",
        To:      []string{"user@example.com"},
        Subject: "Hello",
        HTML:    "<p>It works.</p>",
    })
    if err != nil {
        log.Fatalf("send: %v", err)
    }
    log.Printf("sent: %s", res.ID)
}

4. Verify your sending domain

Live sends require ownership of the FROM domain. Add it at /domains and paste the DKIM/SPF/DMARC records into your DNS host.

5. Send a batch

go
res, err := ms.Batch.Send([]*mailstorm.SendRequest{
    {From: "alerts@yourdomain.com", To: []string{"a@example.com"}, Subject: "x", HTML: "<p>1</p>"},
    {From: "alerts@yourdomain.com", To: []string{"b@example.com"}, Subject: "y", HTML: "<p>2</p>"},
})

6. Idempotency

go
ms.Emails.Send(&mailstorm.SendRequest{
    From: "...", To: []string{"..."},
    Subject: "Order confirmation",
    HTML: "...",
}, mailstorm.WithIdempotencyKey("order-12345"))

7. Context + timeouts

The SDK accepts a context.Context on every method for cancellation and deadlines. Use it in any HTTP handler that already has a context.

handler.go
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()

ms.Emails.SendWithContext(ctx, &mailstorm.SendRequest{...})

What's next