Documentation
¶
Overview ¶
Package quolle is the official Go client for the Quolle email API.
client := quolle.New("qle_...")
res, err := client.Emails.Send(context.Background(), quolle.SendParams{
From: "hello@mail.yourdomain.com",
To: quolle.To("customer@example.com"),
Subject: "Welcome!",
HTML: "<h1>Thanks for signing up</h1>",
})
if err != nil { log.Fatal(err) }
fmt.Println(res.ID)
Index ¶
- Constants
- func VerifyWebhook(payload []byte, signatureHeader, secret string, tolerance time.Duration) error
- type Attachment
- type BatchResult
- type CancelResult
- type Client
- type Email
- type Emails
- func (e *Emails) Cancel(ctx context.Context, id string) (*CancelResult, error)
- func (e *Emails) Get(ctx context.Context, id string) (*Email, error)
- func (e *Emails) Send(ctx context.Context, params SendParams, opts ...SendOption) (*SendResult, error)
- func (e *Emails) SendBatch(ctx context.Context, emails []SendParams, opts ...SendOption) (*BatchResult, error)
- type Error
- type Option
- type Recipients
- type SendOption
- type SendParams
- type SendResult
Constants ¶
const DefaultWebhookTolerance = 5 * time.Minute
DefaultWebhookTolerance is the max age of a webhook timestamp before it's rejected as a possible replay.
const Version = "1.0.0"
Version is the SDK version, sent in the User-Agent header.
Variables ¶
This section is empty.
Functions ¶
func VerifyWebhook ¶
VerifyWebhook checks that a webhook payload really came from Quolle.
Pass the RAW request body, the value of the "Quolle-Signature" header, and your webhook signing secret (whsec_…, shown once when you created the webhook). Returns nil on success, or an error if the header is malformed, the timestamp is outside the tolerance window, or the signature doesn't match.
if err := quolle.VerifyWebhook(body, r.Header.Get("Quolle-Signature"), secret, 0); err != nil {
http.Error(w, "invalid signature", http.StatusBadRequest)
return
}
Types ¶
type Attachment ¶
type Attachment struct {
Filename string `json:"filename"`
Content string `json:"content,omitempty"`
Path string `json:"path,omitempty"`
ContentType string `json:"contentType,omitempty"`
ContentID string `json:"contentId,omitempty"`
}
Attachment is a file attached to an email. Provide either Content (the raw file bytes, base64-encoded) or Path (a URL Quolle fetches at send time). Set ContentID to embed the file inline via <img src="cid:the-id">. Up to 20 attachments, 10 MB total.
func FileAttachment ¶
func FileAttachment(path string) (Attachment, error)
FileAttachment reads a file from disk and returns an Attachment with its base64-encoded content and a content type guessed from the extension.
type BatchResult ¶
BatchResult is returned by SendBatch.
type CancelResult ¶
type CancelResult struct {
Message string `json:"message"`
}
CancelResult is returned by Cancel.
type Client ¶
type Client struct {
// Emails exposes the email operations (Send, SendBatch, Get, Cancel).
Emails *Emails
// contains filtered or unexported fields
}
Client is the Quolle API client. Create one with New.
type Email ¶
type Email struct {
ID string `json:"id"`
From string `json:"from"`
To string `json:"to"`
Subject string `json:"subject"`
Status string `json:"status"`
Provider string `json:"provider"`
MessageID string `json:"messageId"`
OpensCount int `json:"opensCount"`
ClicksCount int `json:"clicksCount"`
SentAt string `json:"sentAt"`
DeliveredAt string `json:"deliveredAt"`
BouncedAt string `json:"bouncedAt"`
CreatedAt string `json:"createdAt"`
}
Email is a retrieved email record.
type Emails ¶
type Emails struct {
// contains filtered or unexported fields
}
Emails provides email operations. Access it via Client.Emails.
func (*Emails) Send ¶
func (e *Emails) Send(ctx context.Context, params SendParams, opts ...SendOption) (*SendResult, error)
Send queues an email for immediate or scheduled delivery.
func (*Emails) SendBatch ¶
func (e *Emails) SendBatch(ctx context.Context, emails []SendParams, opts ...SendOption) (*BatchResult, error)
SendBatch sends up to 100 emails in one all-or-nothing request.
type Error ¶
type Error struct {
// StatusCode is the HTTP status code.
StatusCode int
// Message is the human-readable error (from the API's "error" field).
Message string
// Data holds any extra fields returned alongside "error".
Data map[string]any
}
Error is returned when the API responds with a non-2xx status.
type Option ¶
type Option func(*Client)
Option customizes a Client.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (default https://api.quolle.com).
func WithHTTPClient ¶
WithHTTPClient supplies a custom *http.Client (e.g. with a proxy or timeout).
func WithMaxRetries ¶
WithMaxRetries sets how many times to retry transient failures (default 3).
type Recipients ¶
type Recipients struct {
// contains filtered or unexported fields
}
Recipients is the value for the To field: one or many addresses. Use To or ToMany to construct it. It marshals to a JSON string for a single recipient and a JSON array for multiple, matching the API.
func (Recipients) MarshalJSON ¶
func (r Recipients) MarshalJSON() ([]byte, error)
MarshalJSON emits a bare string for one recipient, an array for many.
type SendOption ¶
SendOption customizes a single Send/SendBatch call.
func WithIdempotencyKey ¶
func WithIdempotencyKey(key string) SendOption
WithIdempotencyKey makes a send safe to retry — the same key returns the original result instead of sending twice.
type SendParams ¶
type SendParams struct {
From string `json:"from"`
To Recipients `json:"to"`
Subject string `json:"subject,omitempty"`
HTML string `json:"html,omitempty"`
Text string `json:"text,omitempty"`
Template string `json:"template,omitempty"`
Variables map[string]any `json:"variables,omitempty"`
ReplyTo string `json:"replyTo,omitempty"`
ScheduledAt string `json:"scheduledAt,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
SendParams are the fields for a single send. Provide either HTML (with Subject) or Template (with optional Variables).