Skip to main content

Go

Use the official Go SDK with Go 1.26 or later.

Before you start​

You need a verified sending domain and an API key with the sending scope. Set EPOSTIX_API_KEY in your environment.

Install​

From a Go module:

go get github.com/epostix/sdk-go

Send an email​

Replace the sender with an address at your verified domain and the recipient with your own address.

main.go
package main

import (
"context"
"errors"
"fmt"
"log"
"os"
"time"

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

func main() {
client := epostix.New(os.Getenv("EPOSTIX_API_KEY"))
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

html := "<p>Sent with Epostix.</p>"
text := "Sent with Epostix."
email, err := client.Emails.SendEmail(ctx, &epostix.EmailCreate{
From: epostix.Addr("hello@mail.yourdomain.com"),
To: []string{"you@yourdomain.com"},
Subject: "Your first email",
HTML: &html,
Text: &text,
}, epostix.WithIdempotencyKey("first-email-001"))
if err != nil {
var apiErr *epostix.APIError
if errors.As(err, &apiErr) {
log.Printf("type=%s request_id=%s", apiErr.Type, apiErr.RequestID)
}
log.Fatal(err)
}

fmt.Println(email.ID)
}
go run .

The ID confirms acceptance. Check Activity or subscribe to webhooks to follow delivery.

Context and retries​

In a server or worker, pass the operation's context so cancellation reaches the SDK. The client retries eligible transient failures within its retry budget and the context deadline.

Reuse the same idempotency key for the same logical send, including after a worker restart. The key in this example deduplicates repeats for 24 hours; use a new one for a new message. See idempotency for the exact scope.

Test without delivering​

Use a test API key or send to delivered@epostix.dev. Domain verification still applies. See test mode for the other simulated outcomes.

Next​