exx

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 30 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

exx-go

Go SDK for the exx.sh email API, on the standard library's HTTP and SMTP clients.

go get github.com/souravsspace/exx-go
client := exx.NewClient(os.Getenv("EXX_API_KEY"))
sent, err := client.Emails.Send(ctx, &exx.SendEmailRequest{
	From:    "Acme <hi@acme.com>",
	To:      []string{"user@example.com"},
	Subject: "Hello",
	Html:    "<p>It works.</p>",
})

Every method takes a context.Context first; it bounds the whole call, retries included. Errors are *exx.Error with Name (the API's error name, for server errors too), Message and StatusCode (0 with application_error when no answer came back; errors.Unwrap gives the transport error). An answer that is not the API's (a proxy's HTML page) is application_error with its status, and an id that is not a UUID is invalid_parameter with 422 before any request.

  • Services: Emails (Send, Get, List, Update, Cancel, Attempts, Transcript), Batch, Domains, ApiKeys, Webhooks, Suppressions. SendWithOptions takes exx.SendOptions{IdempotencyKey, Stream}.
  • Options: exx.WithBaseURL, exx.WithHTTPClient, exx.WithRetries (default 2), exx.WithTimeout (per attempt, default 30 s), exx.WithUserAgent.
  • Retries: 429 except a spent quota; 5xx and lost answers when a replay cannot act twice (every request but a POST without an Idempotency-Key; sends get one made for you while retries are on); 409 concurrent_idempotent_requests while the server still runs a keyed send.

SMTP

smtp := exx.NewSMTPClient("") // EXX_API_KEY; smtp.exx.sh:465, TLS
sent, err := smtp.Send(ctx, &exx.SendEmailRequest{From: from, To: to, Subject: "Hi", Text: "hi"}, nil)
// sent.Id is the same id the API and webhooks use

Options: exx.WithSMTPHost, exx.WithSMTPPort (defaults EXX_SMTP_HOST, EXX_SMTP_PORT), exx.WithSMTPImplicitTLS, exx.WithSMTPTLSConfig, exx.WithSMTPTimeout, exx.WithSMTPDialer. Port 465 is TLS from the start, any other port STARTTLS; a refusal is *exx.Error named smtp_error with SMTPCode. Tags, scheduling and attachment paths need the API.

Webhooks

event, err := exx.VerifyWebhook(&exx.VerifyWebhookOptions{
	Payload: string(body), Headers: exx.HeadersFrom(r.Header), WebhookSecret: secret,
})
// event.Type, event.CreatedAt, event.Data (raw JSON)

Docs: https://docs.exx.sh/sdks/go. MIT licensed.

Documentation

Overview

Package exx is the Go SDK of the exx.sh email API: a thin facade over the client generated from openapi/openapi.json (internal/api, never edited by hand).

client := exx.NewClient(os.Getenv("EXX_API_KEY"))
sent, err := client.Emails.Send(ctx, &exx.SendEmailRequest{
	From: "Acme <hi@acme.test>", To: []string{"a@b.test"}, Subject: "Hi", Html: "<p>hi</p>",
})

Every method takes a context first. API errors are *Error with the API's Name; requests that got no answer are *Error with Name "application_error" and no status.

Index

Constants

View Source
const Version = "0.2.0"

Version of this SDK.

Variables

View Source
var ErrWebhookVerification = errors.New("exx: webhook verification failed")

ErrWebhookVerification is wrapped by every refusal of VerifyWebhook.

Functions

This section is empty.

Types

type ApiKeyList

type ApiKeyList = api.ListApiKey

The API's answers, as generated from openapi/openapi.json.

type ApiKeysService

type ApiKeysService struct {
	// contains filtered or unexported fields
}

ApiKeysService manages API keys.

func (*ApiKeysService) Create

func (*ApiKeysService) List

func (*ApiKeysService) Remove

func (x *ApiKeysService) Remove(ctx context.Context, id string) (*Deleted, error)

type Attachment

type Attachment struct {
	Content     string // base64
	Filename    string
	Path        string // a URL exx.sh fetches
	ContentType string
	ContentId   string
}

type AttemptList

type AttemptList = api.ListAttempt

The API's answers, as generated from openapi/openapi.json.

type BatchResult

type BatchResult = api.BatchResult

The API's answers, as generated from openapi/openapi.json.

type BatchService

type BatchService struct {
	// contains filtered or unexported fields
}

BatchService sends up to 100 emails accepted together or not at all.

func (*BatchService) Send

func (x *BatchService) Send(ctx context.Context, emails []*SendEmailRequest) (*BatchResult, error)

func (*BatchService) SendWithOptions

func (x *BatchService) SendWithOptions(ctx context.Context, emails []*SendEmailRequest, o *SendOptions) (*BatchResult, error)

type Capabilities

type Capabilities = api.Capabilities

The API's answers, as generated from openapi/openapi.json.

type Client

type Client struct {
	Emails       *EmailsService
	Batch        *BatchService
	Domains      *DomainsService
	ApiKeys      *ApiKeysService
	Webhooks     *WebhooksService
	Suppressions *SuppressionsService
}

Client is the exx.sh API. Its services share one HTTP client.

func NewClient

func NewClient(apiKey string, opts ...Option) *Client

NewClient makes a client for apiKey ("" reads EXX_API_KEY).

type CreateApiKeyRequest

type CreateApiKeyRequest struct {
	Name       string
	Permission PermissionField // "full_access" (default) or "sending_access"
	DomainId   string
}

type CreateDomainRequest

type CreateDomainRequest struct {
	Name, Region, CustomReturnPath, Tls, TrackingSubdomain string
	OpenTracking, ClickTracking                            *bool
	Capabilities                                           *Capabilities
}

type CreateWebhookRequest

type CreateWebhookRequest struct {
	Endpoint string
	Events   []string
}

type CreatedApiKey

type CreatedApiKey = api.CreatedApiKey

The API's answers, as generated from openapi/openapi.json.

type CreatedWebhook

type CreatedWebhook = api.CreatedWebhook

The API's answers, as generated from openapi/openapi.json.

type Deleted

type Deleted = api.Deleted

The API's answers, as generated from openapi/openapi.json.

type Domain

type Domain = api.DomainView

The API's answers, as generated from openapi/openapi.json.

type DomainList

type DomainList = api.ListDomainView

The API's answers, as generated from openapi/openapi.json.

type DomainRef

type DomainRef = api.DomainRef

The API's answers, as generated from openapi/openapi.json.

type DomainsService

type DomainsService struct {
	// contains filtered or unexported fields
}

DomainsService manages sending domains.

func (*DomainsService) Create

func (*DomainsService) Get

func (x *DomainsService) Get(ctx context.Context, id string) (*Domain, error)

func (*DomainsService) List

func (*DomainsService) Remove

func (x *DomainsService) Remove(ctx context.Context, id string) (*Deleted, error)

func (*DomainsService) Update

func (*DomainsService) Verify

func (x *DomainsService) Verify(ctx context.Context, id string) (*DomainRef, error)

type Email

type Email = api.Email

The API's answers, as generated from openapi/openapi.json.

type EmailId

type EmailId = api.EmailId

The API's answers, as generated from openapi/openapi.json.

type EmailList

type EmailList = api.ListEmailSummary

The API's answers, as generated from openapi/openapi.json.

type EmailRef

type EmailRef = api.EmailRef

The API's answers, as generated from openapi/openapi.json.

type EmailsService

type EmailsService struct {
	// contains filtered or unexported fields
}

EmailsService sends and reads emails.

func (*EmailsService) Attempts

func (x *EmailsService) Attempts(ctx context.Context, id string) (*AttemptList, error)

Attempts lists the delivery attempts with their SMTP replies (exx only).

func (*EmailsService) Cancel

func (x *EmailsService) Cancel(ctx context.Context, id string) (*EmailRef, error)

func (*EmailsService) Get

func (x *EmailsService) Get(ctx context.Context, id string) (*Email, error)

func (*EmailsService) List

func (x *EmailsService) List(ctx context.Context, o *ListOptions) (*EmailList, error)

func (*EmailsService) Send

Send sends one email and returns its id.

func (*EmailsService) SendWithOptions

func (x *EmailsService) SendWithOptions(ctx context.Context, e *SendEmailRequest, o *SendOptions) (*EmailId, error)

func (*EmailsService) Transcript

func (x *EmailsService) Transcript(ctx context.Context, id, attemptID string) (map[string]any, error)

Transcript is the SMTP transcript of one attempt (exx only).

func (*EmailsService) Update

Update moves a scheduled email.

type Error

type Error struct {
	Name       string
	Message    string
	StatusCode int // 0 when the request got no answer
	SMTPCode   int // the reply code of an SMTP refusal ("smtp_error"), else 0
	// contains filtered or unexported fields
}

Error is an exx.sh API error (Name as in the API reference) or "application_error".

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap gives the transport error of a request that got no answer.

type ListOptions

type ListOptions struct {
	Limit         int
	After, Before string
}

ListOptions pages a list.

type Option

type Option func(*config)

Option configures a Client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL sets the API's URL (default EXX_BASE_URL, then https://api.exx.sh).

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sends through a copy of hc (its Transport gets the retries).

func WithRetries

func WithRetries(n int) Option

WithRetries sets the retries of rate-limited, failed or unanswered requests (default 2).

func WithSleep

func WithSleep(sleep func(time.Duration)) Option

WithSleep replaces the wait between retries (tests).

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the time per attempt (default 30 s): an attempt that times out is retried like a lost answer; the context passed to each call bounds the whole call. With WithHTTPClient the client's own Timeout applies too.

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent replaces the User-Agent header.

type PermissionField

type PermissionField = api.PermissionField

The API's answers, as generated from openapi/openapi.json.

type SMTPClient

type SMTPClient struct {
	// contains filtered or unexported fields
}

SMTPClient sends the API's email shape over SMTP submission (smtp.exx.sh, user "exx", the API key as password): TLS from the start on port 465, STARTTLS on any other port (required: the key never travels in the clear). The email gets an id, attempts and webhook events like one sent with the API.

func NewSMTPClient

func NewSMTPClient(apiKey string, opts ...SMTPOption) *SMTPClient

NewSMTPClient makes an SMTP client for apiKey ("" reads EXX_API_KEY).

func (*SMTPClient) Send

Send submits one email over one connection and returns its id. A refusal is *Error with Name "smtp_error" and its SMTPCode; o may be nil.

type SMTPOption

type SMTPOption func(*SMTPClient)

SMTPOption configures an SMTPClient.

func WithSMTPDialer

func WithSMTPDialer(dial func(ctx context.Context, network, addr string) (net.Conn, error)) SMTPOption

WithSMTPDialer replaces how the TCP connection is made (proxies, tests).

func WithSMTPHost

func WithSMTPHost(host string) SMTPOption

WithSMTPHost sets the server (default EXX_SMTP_HOST, then smtp.exx.sh).

func WithSMTPImplicitTLS

func WithSMTPImplicitTLS(on bool) SMTPOption

WithSMTPImplicitTLS chooses TLS from the start (true) or STARTTLS (false); the default is TLS from the start on port 465.

func WithSMTPPort

func WithSMTPPort(port int) SMTPOption

WithSMTPPort sets the port (default EXX_SMTP_PORT, then 465).

func WithSMTPTLSConfig

func WithSMTPTLSConfig(cfg *tls.Config) SMTPOption

WithSMTPTLSConfig sets the TLS configuration (e.g. RootCAs for a private stack).

func WithSMTPTimeout

func WithSMTPTimeout(d time.Duration) SMTPOption

WithSMTPTimeout bounds one send, connection included (default 30 s).

type SendEmailRequest

type SendEmailRequest struct {
	From        string
	To          []string
	Subject     string
	Html        string
	Text        string
	Cc          []string
	Bcc         []string
	ReplyTo     []string
	Headers     map[string]string
	Attachments []Attachment
	Tags        []Tag
	// ScheduledAt is ISO 8601, or `in <n> <minutes|hours|days>`.
	ScheduledAt string
}

SendEmailRequest is one email (Resend's fields; empty means unset).

type SendOptions

type SendOptions struct{ IdempotencyKey, Stream string }

SendOptions of a send; without an IdempotencyKey one is made when the call may retry. Stream is the sending stream (exx only): "transactional" (the default) or "distributional".

type SuppressionList

type SuppressionList = api.ListSuppression

The API's answers, as generated from openapi/openapi.json.

type SuppressionRef

type SuppressionRef = api.SuppressionRef

The API's answers, as generated from openapi/openapi.json.

type SuppressionsService

type SuppressionsService struct {
	// contains filtered or unexported fields
}

SuppressionsService manages the project's suppression list.

func (*SuppressionsService) Add

func (*SuppressionsService) List

List lists newest first; After is the last address of the previous page (Before is not used).

func (*SuppressionsService) Remove

func (x *SuppressionsService) Remove(ctx context.Context, email string) (*SuppressionRef, error)

type Tag

type Tag struct{ Name, Value string }

type UpdateDomainRequest

type UpdateDomainRequest struct {
	OpenTracking, ClickTracking *bool
	Tls, TrackingSubdomain      string
	Capabilities                *Capabilities
}

type UpdateEmailRequest

type UpdateEmailRequest struct{ ScheduledAt string }

type UpdateWebhookRequest

type UpdateWebhookRequest struct {
	Endpoint string
	Events   []string
	Status   string // "enabled" or "disabled"
}

type VerifyWebhookOptions

type VerifyWebhookOptions struct {
	Payload       string // the raw body, exactly as received
	Headers       WebhookHeaders
	WebhookSecret string        // the endpoint's signing secret (whsec_…)
	Tolerance     time.Duration // how far the timestamp may be from now (default 5 min)
	Now           time.Time     // default time.Now (tests)
}

VerifyWebhookOptions of one delivery.

type Webhook

type Webhook = api.Webhook

The API's answers, as generated from openapi/openapi.json.

type WebhookEvent

type WebhookEvent struct {
	Type      string          `json:"type"`
	CreatedAt string          `json:"created_at"`
	Data      json.RawMessage `json:"data"`
}

WebhookEvent is a verified delivery's payload: `data` stays raw JSON, its shape depends on `type` (see the webhooks guide).

func VerifyWebhook

func VerifyWebhook(o *VerifyWebhookOptions) (*WebhookEvent, error)

VerifyWebhook checks a delivery (Standard Webhooks, the svix scheme): HMAC-SHA256 over `{id}.{timestamp}.{payload}`, any of the `v1,` signatures, compared in constant time. It returns the parsed event, like the other SDKs.

type WebhookHeaders

type WebhookHeaders struct{ Id, Timestamp, Signature string }

WebhookHeaders are a delivery's svix-id, svix-timestamp and svix-signature.

func HeadersFrom

func HeadersFrom(h http.Header) WebhookHeaders

HeadersFrom reads the svix-* (or webhook-*) headers of a request.

type WebhookList

type WebhookList = api.ListWebhook

The API's answers, as generated from openapi/openapi.json.

type WebhookRef

type WebhookRef = api.WebhookRef

The API's answers, as generated from openapi/openapi.json.

type WebhooksService

type WebhooksService struct {
	// contains filtered or unexported fields
}

WebhooksService manages webhook endpoints and verifies their deliveries.

func (*WebhooksService) Create

func (*WebhooksService) Get

func (x *WebhooksService) Get(ctx context.Context, id string) (*Webhook, error)

func (*WebhooksService) List

func (*WebhooksService) Remove

func (x *WebhooksService) Remove(ctx context.Context, id string) (*Deleted, error)

func (*WebhooksService) RotateSigningSecret

func (x *WebhooksService) RotateSigningSecret(ctx context.Context, id string) (*CreatedWebhook, error)

func (*WebhooksService) Update

func (*WebhooksService) Verify

Verify checks a delivery's signature and returns its event (see VerifyWebhook).

Directories

Path Synopsis
examples
send command
`EXX_API_KEY=exx_...
`EXX_API_KEY=exx_...
internal
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL