uSend Docs
Quickstarts

Send with Go

Send email from Go with the usend Go SDK.

You need a verified domain and an API key.

1. Install

Shell
go get usend.et/sdk/go

The SDK uses only the standard library.

2. Send

main.go
package main

import (
	"context"
	"errors"
	"fmt"
	"os"

	usend "usend.et/sdk/go"
)

func main() {
	client, err := usend.New(os.Getenv("USEND_API_KEY"))
	if err != nil {
		panic(err)
	}

	res, err := client.Emails.Send(context.Background(), &usend.SendEmailParams{
		From:    "Acme <[email protected]>",
		To:      []string{"[email protected]"},
		Subject: "Hello from usend",
		HTML:    "<p>It works!</p>",
	}, usend.WithIdempotencyKey("welcome-ann-1"))
	if err != nil {
		var apiErr *usend.Error
		if errors.As(err, &apiErr) {
			fmt.Printf("usend %d %s: %s\n", apiErr.StatusCode, apiErr.Name, apiErr.Message)
		} else {
			fmt.Println("failed:", err)
		}
		os.Exit(1)
	}
	fmt.Println("queued", res.ID)
}
Shell
USEND_API_KEY=us_123456789 go run .

Notes

  • The client retries 429 (honoring Retry-After) and, for requests with an idempotency key, 5xx (Idempotency). Tune it with usend.WithMaxRetries.
  • Receiving webhooks? usend.VerifyWebhook(body, r.Header, secret) checks the signature over the raw body: Verify signatures.
  • SMTP instead of the API: client.SMTPConfig(587) returns the host, port and credentials (SMTP).
  • No SDK? The API is one JSON POST to https://api.usend.et/emails with an Authorization: Bearer header, so net/http works too.

More fields: Send emails. Rust version: Send with Rust.