Documentation
¶
Overview ¶
Package vibemail is the official Go SDK for the VibeMail transactional email API.
The surface here is limited to endpoints the API actually serves. An Analytics method existed in an earlier draft and returned 404 against every deployment; it is absent rather than broken, and will return when the endpoint does.
Index ¶
- Constants
- Variables
- func Bool(b bool) *bool
- type BatchResponse
- type BatchResult
- type Client
- func (c *Client) Batch(ctx context.Context, emails []SendRequest, opts ...SendOption) (*BatchResponse, error)
- func (c *Client) Cancel(ctx context.Context, id string) (*SendResponse, error)
- func (c *Client) Contacts(ctx context.Context, opts ListOptions) (*Page[Contact], error)
- func (c *Client) CreateContact(ctx context.Context, email, name, notes string) (*Contact, error)
- func (c *Client) CreateDomain(ctx context.Context, domain string) (*Domain, error)
- func (c *Client) DeleteContact(ctx context.Context, id string) (*Deleted, error)
- func (c *Client) DeleteDomain(ctx context.Context, id string) (*Deleted, error)
- func (c *Client) Domain(ctx context.Context, id string) (*Domain, error)
- func (c *Client) Domains(ctx context.Context, opts ListOptions) (*Page[Domain], error)
- func (c *Client) Get(ctx context.Context, id string) (*SendResponse, error)
- func (c *Client) Send(ctx context.Context, req SendRequest, opts ...SendOption) (*SendResponse, error)
- func (c *Client) Suppressions(ctx context.Context, opts ListOptions) (*Page[Suppression], error)
- func (c *Client) Templates(ctx context.Context) ([]Template, error)
- type Contact
- type DNSRecord
- type Deleted
- type Domain
- type Error
- type ListOptions
- type Option
- type Page
- type SendOption
- type SendRequest
- type SendResponse
- type Suppression
- type Template
Constants ¶
const Version = "1.2.0"
Version of this SDK, reported in the User-Agent.
Variables ¶
var ErrNoRecipient = errors.New("vibemail: To must contain a recipient address")
ErrNoRecipient is returned when To is empty.
var ErrTooManyRecipients = errors.New(
"vibemail: To takes a single address, use Batch to send to several recipients, " +
"since one message addressed to many would disclose the list to all of them")
ErrTooManyRecipients is returned when Send is given more than one address. The API delivers to a single recipient and derives per-domain rate limiting from it; silently taking the first would drop the rest with no error.
Functions ¶
Types ¶
type BatchResponse ¶
type BatchResponse struct {
Data []BatchResult `json:"data"`
}
BatchResponse holds one entry per message, in the order submitted.
type BatchResult ¶
type BatchResult struct {
ID string `json:"id,omitempty"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
}
BatchResult is either an accepted message or the reason it was rejected.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the VibeMail API. It is safe for concurrent use.
func (*Client) Batch ¶
func (c *Client) Batch(ctx context.Context, emails []SendRequest, opts ...SendOption) (*BatchResponse, error)
Batch sends several messages in one request, one recipient each. Entries succeed or fail individually.
func (*Client) Cancel ¶
Cancel withdraws a scheduled send, while it is still scheduled. Once the dispatcher has claimed it the message is on its way out.
func (*Client) Contacts ¶ added in v1.2.0
Contacts lists contacts. Set ListOptions.Search to match address or name.
func (*Client) CreateContact ¶ added in v1.2.0
CreateContact stores a contact. Empty name and notes are left off the wire.
func (*Client) CreateDomain ¶ added in v1.2.0
CreateDomain adds a domain. The reply carries the records to publish; the domain stays unverified until they resolve.
func (*Client) DeleteContact ¶ added in v1.2.0
DeleteContact forgets a contact.
func (*Client) DeleteDomain ¶ added in v1.2.0
DeleteDomain removes a domain. Mail already sent from it is unaffected.
func (*Client) Domain ¶ added in v1.2.0
Domain reads one domain, including the DNS records that verify it.
func (*Client) Send ¶
func (c *Client) Send(ctx context.Context, req SendRequest, opts ...SendOption) (*SendResponse, error)
Send delivers one message.
func (*Client) Suppressions ¶ added in v1.2.0
func (c *Client) Suppressions(ctx context.Context, opts ListOptions) (*Page[Suppression], error)
Suppressions lists addresses that will not be sent to: hard bounces, complaints and manual blocks. A send to one of these is dropped rather than attempted.
type Contact ¶ added in v1.2.0
type Contact struct {
ID int64 `json:"id"`
Email string `json:"email"`
Name string `json:"name,omitempty"`
Notes string `json:"notes,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
}
Contact is a stored contact.
type DNSRecord ¶ added in v1.2.0
type DNSRecord struct {
Type string `json:"type"`
// Host is the record name to create, fully qualified.
Host string `json:"host"`
Value string `json:"value"`
Priority int `json:"priority,omitempty"`
}
DNSRecord is a record to publish so a domain can be verified.
type Deleted ¶ added in v1.2.0
type Deleted struct {
Deleted bool `json:"deleted"`
Domain string `json:"domain,omitempty"`
Email string `json:"email,omitempty"`
}
Deleted is the outcome of a delete.
type Domain ¶ added in v1.2.0
type Domain struct {
ID int64 `json:"id"`
Domain string `json:"domain"`
IsVerified bool `json:"is_verified"`
VerificationToken string `json:"verification_token,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
// DNSRecords is returned by Domain and CreateDomain, keyed by purpose:
// "verification", "mx", "spf", "dmarc".
DNSRecords map[string]DNSRecord `json:"dns_records,omitempty"`
}
Domain is a sending domain on the account.
type Error ¶
type Error struct {
StatusCode int
// Detail is the API's "error" field when the body was JSON.
Detail string
// Body is the raw response, for anything Detail does not capture.
Body string
// RetryAfter is the server's requested wait on a 429, if it sent one.
RetryAfter time.Duration
}
Error is a non-2xx response from the API.
type ListOptions ¶ added in v1.2.0
type ListOptions struct {
// Limit defaults to 50 and is capped at 100.
Limit int
// Offset skips records.
Offset int
// Search matches address or name. Only honoured by Contacts.
Search string
}
ListOptions is paging for the list endpoints. The zero value asks for the server defaults.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL points the client at a different deployment.
func WithHTTPClient ¶
WithHTTPClient supplies your own *http.Client, for a custom transport, proxy, or a stub in tests. Its Timeout governs each attempt.
func WithMaxRetries ¶
WithMaxRetries sets how many times a 429 or 5xx is retried. Zero disables retrying. Requests the server rejected on their merits are never retried.
type Page ¶ added in v1.2.0
type Page[T any] struct { Object string `json:"object"` Total int64 `json:"total"` Limit int64 `json:"limit"` Offset int64 `json:"offset"` Data []T `json:"data"` }
Page is one page of results. Total counts everything matching, not just this page.
type SendOption ¶
type SendOption func(*sendOptions)
SendOption configures a single Send or Batch call.
func WithIdempotencyKey ¶
func WithIdempotencyKey(key string) SendOption
WithIdempotencyKey makes a retry safe: a repeat carrying the same key returns the original result instead of sending a second copy. A client that times out cannot otherwise tell whether the message went out.
type SendRequest ¶
type SendRequest struct {
// To is the recipient. Exactly one, see Batch for several.
To string `json:"to"`
// From must be an address your account owns. Defaults to the account address.
From string `json:"from,omitempty"`
// Subject is required unless a Template supplies one.
Subject string `json:"subject,omitempty"`
Text string `json:"text,omitempty"`
HTML string `json:"html,omitempty"`
// Template is the name or id of a stored template. Explicit fields win over it.
Template string `json:"template,omitempty"`
Variables map[string]string `json:"variables,omitempty"`
Tags []string `json:"tags,omitempty"`
// TrackOpens and TrackClicks apply to HTML sends. Both default to on;
// pointers distinguish "leave the default" from an explicit false.
TrackOpens *bool `json:"track_opens,omitempty"`
TrackClicks *bool `json:"track_clicks,omitempty"`
// ScheduledAt takes an RFC 3339 timestamp or a relative offset such as
// "in 2 hours", up to 30 days ahead. Use ScheduleAt to set it from a time.Time.
ScheduledAt string `json:"scheduled_at,omitempty"`
}
SendRequest is one outbound message.
func (*SendRequest) ScheduleAt ¶
func (r *SendRequest) ScheduleAt(t time.Time)
ScheduleAt sets ScheduledAt from a time.Time, in UTC.
type SendResponse ¶
type SendResponse struct {
ID string `json:"id"`
Status string `json:"status"`
ScheduledAt string `json:"scheduled_at,omitempty"`
}
SendResponse is the API's acknowledgement. It means the message was accepted, not that it was delivered.
type Suppression ¶ added in v1.2.0
type Suppression struct {
Email string `json:"email"`
Reason string `json:"reason,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
}
Suppression is an address that will not be sent to.