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
- Variables
- type ApiKeyList
- type ApiKeysService
- type Attachment
- type AttemptList
- type BatchResult
- type BatchService
- type Capabilities
- type Client
- type CreateApiKeyRequest
- type CreateDomainRequest
- type CreateWebhookRequest
- type CreatedApiKey
- type CreatedWebhook
- type Deleted
- type Domain
- type DomainList
- type DomainRef
- type DomainsService
- func (x *DomainsService) Create(ctx context.Context, r *CreateDomainRequest) (*Domain, error)
- func (x *DomainsService) Get(ctx context.Context, id string) (*Domain, error)
- func (x *DomainsService) List(ctx context.Context, o *ListOptions) (*DomainList, error)
- func (x *DomainsService) Remove(ctx context.Context, id string) (*Deleted, error)
- func (x *DomainsService) Update(ctx context.Context, id string, r *UpdateDomainRequest) (*DomainRef, error)
- func (x *DomainsService) Verify(ctx context.Context, id string) (*DomainRef, error)
- type Email
- type EmailId
- type EmailList
- type EmailRef
- type EmailsService
- func (x *EmailsService) Attempts(ctx context.Context, id string) (*AttemptList, error)
- func (x *EmailsService) Cancel(ctx context.Context, id string) (*EmailRef, error)
- func (x *EmailsService) Get(ctx context.Context, id string) (*Email, error)
- func (x *EmailsService) List(ctx context.Context, o *ListOptions) (*EmailList, error)
- func (x *EmailsService) Send(ctx context.Context, e *SendEmailRequest) (*EmailId, error)
- func (x *EmailsService) SendWithOptions(ctx context.Context, e *SendEmailRequest, o *SendOptions) (*EmailId, error)
- func (x *EmailsService) Transcript(ctx context.Context, id, attemptID string) (map[string]any, error)
- func (x *EmailsService) Update(ctx context.Context, id string, r *UpdateEmailRequest) (*EmailRef, error)
- type Error
- type ListOptions
- type Option
- type PermissionField
- type SMTPClient
- type SMTPOption
- func WithSMTPDialer(dial func(ctx context.Context, network, addr string) (net.Conn, error)) SMTPOption
- func WithSMTPHost(host string) SMTPOption
- func WithSMTPImplicitTLS(on bool) SMTPOption
- func WithSMTPPort(port int) SMTPOption
- func WithSMTPTLSConfig(cfg *tls.Config) SMTPOption
- func WithSMTPTimeout(d time.Duration) SMTPOption
- type SendEmailRequest
- type SendOptions
- type SuppressionList
- type SuppressionRef
- type SuppressionsService
- type Tag
- type UpdateDomainRequest
- type UpdateEmailRequest
- type UpdateWebhookRequest
- type VerifyWebhookOptions
- type Webhook
- type WebhookEvent
- type WebhookHeaders
- type WebhookList
- type WebhookRef
- type WebhooksService
- func (x *WebhooksService) Create(ctx context.Context, r *CreateWebhookRequest) (*CreatedWebhook, error)
- func (x *WebhooksService) Get(ctx context.Context, id string) (*Webhook, error)
- func (x *WebhooksService) List(ctx context.Context, o *ListOptions) (*WebhookList, error)
- func (x *WebhooksService) Remove(ctx context.Context, id string) (*Deleted, error)
- func (x *WebhooksService) RotateSigningSecret(ctx context.Context, id string) (*CreatedWebhook, error)
- func (x *WebhooksService) Update(ctx context.Context, id string, r *UpdateWebhookRequest) (*WebhookRef, error)
- func (x *WebhooksService) Verify(o *VerifyWebhookOptions) (*WebhookEvent, error)
Constants ¶
const Version = "0.2.0"
Version of this SDK.
Variables ¶
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 (x *ApiKeysService) Create(ctx context.Context, r *CreateApiKeyRequest) (*CreatedApiKey, error)
func (*ApiKeysService) List ¶
func (x *ApiKeysService) List(ctx context.Context, o *ListOptions) (*ApiKeyList, error)
type Attachment ¶
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.
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 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 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 DomainsService ¶
type DomainsService struct {
// contains filtered or unexported fields
}
DomainsService manages sending domains.
func (*DomainsService) Create ¶
func (x *DomainsService) Create(ctx context.Context, r *CreateDomainRequest) (*Domain, error)
func (*DomainsService) List ¶
func (x *DomainsService) List(ctx context.Context, o *ListOptions) (*DomainList, error)
func (*DomainsService) Update ¶
func (x *DomainsService) Update(ctx context.Context, id string, r *UpdateDomainRequest) (*DomainRef, error)
type EmailList ¶
type EmailList = api.ListEmailSummary
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) List ¶
func (x *EmailsService) List(ctx context.Context, o *ListOptions) (*EmailList, error)
func (*EmailsService) Send ¶
func (x *EmailsService) Send(ctx context.Context, e *SendEmailRequest) (*EmailId, error)
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 ¶
func (x *EmailsService) Update(ctx context.Context, id string, r *UpdateEmailRequest) (*EmailRef, error)
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".
type ListOptions ¶
ListOptions pages a list.
type Option ¶
type Option func(*config)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL sets the API's URL (default EXX_BASE_URL, then https://api.exx.sh).
func WithHTTPClient ¶
WithHTTPClient sends through a copy of hc (its Transport gets the retries).
func WithRetries ¶
WithRetries sets the retries of rate-limited, failed or unanswered requests (default 2).
func WithTimeout ¶
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 ¶
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 ¶
func (c *SMTPClient) Send(ctx context.Context, e *SendEmailRequest, o *SendOptions) (*EmailId, error)
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 (x *SuppressionsService) Add(ctx context.Context, email string) (*SuppressionRef, error)
func (*SuppressionsService) List ¶
func (x *SuppressionsService) List(ctx context.Context, o *ListOptions) (*SuppressionList, error)
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 UpdateDomainRequest ¶
type UpdateDomainRequest struct {
OpenTracking, ClickTracking *bool
Tls, TrackingSubdomain string
Capabilities *Capabilities
}
type UpdateEmailRequest ¶
type UpdateEmailRequest struct{ ScheduledAt string }
type UpdateWebhookRequest ¶
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 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 (x *WebhooksService) Create(ctx context.Context, r *CreateWebhookRequest) (*CreatedWebhook, error)
func (*WebhooksService) List ¶
func (x *WebhooksService) List(ctx context.Context, o *ListOptions) (*WebhookList, error)
func (*WebhooksService) RotateSigningSecret ¶
func (x *WebhooksService) RotateSigningSecret(ctx context.Context, id string) (*CreatedWebhook, error)
func (*WebhooksService) Update ¶
func (x *WebhooksService) Update(ctx context.Context, id string, r *UpdateWebhookRequest) (*WebhookRef, error)
func (*WebhooksService) Verify ¶
func (x *WebhooksService) Verify(o *VerifyWebhookOptions) (*WebhookEvent, error)
Verify checks a delivery's signature and returns its event (see VerifyWebhook).