Skip to content

Send Emails with Go

Learn how to send transactional emails using PostStack and Go.

1. Install the SDK

bash
go get github.com/getpoststack/go-sdk

2. Initialize the client

go
import (
    "context"

    "github.com/getpoststack/go-sdk"
)

client := poststack.NewClient("sk_live_...")

3. Send an email

go
package main

import (
    "context"
    "errors"
    "fmt"
    "log"

    "github.com/getpoststack/go-sdk"
)

func main() {
    client := poststack.NewClient("sk_live_...")

    result, err := client.Emails.Send(context.Background(), map[string]any{
        "from":    "hello@yourdomain.com",
        "to":      []string{"user@example.com"},
        "subject": "Hello from Go!",
        "html":    "<h1>Welcome!</h1>",
    })
    if err != nil {
        var apiErr *poststack.Error
        if errors.As(err, &apiErr) {
            log.Fatalf("API error %d: %s", apiErr.StatusCode, apiErr.Message)
        }
        log.Fatal(err)
    }
    fmt.Println(result["id"])
}

Notes

  • Official Go SDK — stdlib-only, zero external dependencies
  • Requires Go 1.21+

Ready to send emails with Go?

Create a free account and get your API key in under a minute.