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) Get(ctx context.Context, id string) (*SendResponse, error)
- func (c *Client) Send(ctx context.Context, req SendRequest, opts ...SendOption) (*SendResponse, error)
- func (c *Client) Templates(ctx context.Context) ([]Template, error)
- type Error
- type Option
- type SendOption
- type SendRequest
- type SendResponse
- type Template
Constants ¶
const Version = "1.0.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) Send ¶
func (c *Client) Send(ctx context.Context, req SendRequest, opts ...SendOption) (*SendResponse, error)
Send delivers one message.
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 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 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.