docs
SDKs

Go

The module github.com/clowk-in/1billion-go sends mail with the standard library only.

go get github.com/clowk-in/1billion-go

Go 1.24 or newer. The package name is onebillion: a Go name can not start with a digit.

client := onebillion.New("") // the key of ONEBILLION_API_KEY

out, err := client.Emails.Send(ctx, onebillion.Mail{
	From:     "Acme <hi@acme.com>",
	To:       []string{"jane@example.com"},
	Subject:  "Your code",
	Text:     "Your code is 482 913",
	Priority: "high",
}, onebillion.IdempotencyKey("login-jane-482913"))

msg, err := client.Message(ctx, out.Messages[0].ID)
err = client.Unsuppress(ctx, "jane@example.com")
v, err := client.Validate(ctx, "jane@gmial.com")

client.Emails.Send is the same call as client.Send. An empty key reads ONEBILLION_API_KEY.

Verify a webhook

payload, _ := io.ReadAll(r.Body)

event, err := onebillion.VerifySignature(payload, r.Header, "")

An empty secret reads ONEBILLION_WEBHOOK_SECRET. A bad signature or a timestamp more than 5 minutes old gives an error that matches onebillion.ErrInvalidSignature. See Webhooks.

Errors

switch {
case onebillion.NoCredits(err):
	// 429: the credits come back at 00:00 in the time zone of the workspace.
case onebillion.Refused(err):
	// 422: a bad message or a recipient that failed a check.
case err != nil:
	// *onebillion.Error has Status (0 for a network error) and Message.
}

Options

OptionDefaultWhat
WithURLONEBILLION_URL, else the 1billion APIanother console, for example a dev stack
WithHTTPClienta client with a 10 s timeoutyour own *http.Client
WithBackoff500 msthe first wait between tries

Source and changelog: clowk-in/1billion-go.

On this page