The official Go SDK for the Lettr Email API. A typed client for emails, templates, domains, webhooks, audience, and campaigns.
go get github.com/lettr-com/lettr-goRequires Go 1.21 or later.
package main
import (
"context"
"fmt"
"log"
lettr "github.com/lettr-com/lettr-go"
)
func main() {
client := lettr.NewClient("your-api-key")
resp, err := client.Emails.Send(context.Background(), &lettr.SendEmailRequest{
From: "sender@example.com",
To: []string{"recipient@example.com"},
Subject: "Hello from Lettr",
Html: "<h1>Hello!</h1>",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Email sent! Request ID: %s\n", resp.Data.RequestID)
}Methods return a wrapped response (read resp.Data) and a structured error.
The SDK returns typed errors you can inspect with helper predicates:
resp, err := client.Emails.Send(ctx, req)
if err != nil {
switch {
case lettr.IsValidationError(err):
apiErr := err.(*lettr.Error)
for field, messages := range apiErr.Errors {
fmt.Printf("%s: %v\n", field, messages)
}
case lettr.IsUnauthorized(err):
fmt.Println("Invalid API key")
case lettr.IsNotFound(err):
fmt.Println("Resource not found")
default:
fmt.Printf("Error: %v\n", err)
}
}See Error Handling for the full set of predicates.
Full guides for every service, with complete request/response details, live in the docs:
📚 docs.lettr.com/quickstart/go
| Topic | Guide |
|---|---|
| Install, client, sending | Quickstart |
| Batch sending, context & timeouts, error handling | Advanced |
| Manage Lettr templates & merge tags | Templates |
| Add, verify, and manage sending domains | Domains |
| Webhook endpoints for delivery & engagement events | Webhooks |
| Lists, contacts, topics, properties, segments | Audience |
| List, send, and schedule campaigns | Campaigns |
| Endpoint reference (params & schemas) | API Reference |
- Version history: CHANGELOG.md
- Release process: RELEASING.md
This project follows Semantic Versioning.
MIT