Quickstarts
Send with Go
Send email from Go with the usend Go SDK.
You need a verified domain and an API key.
1. Install
go get usend.et/sdk/goThe SDK uses only the standard library.
2. Send
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)
}USEND_API_KEY=us_123456789 go run .Notes
- The client retries
429(honoringRetry-After) and, for requests with an idempotency key,5xx(Idempotency). Tune it withusend.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
POSTtohttps://api.usend.et/emailswith anAuthorization: Bearerheader, sonet/httpworks too.
More fields: Send emails. Rust version: Send with Rust.