Documentation
¶
Overview ¶
Package envloped provides a Go client for the Envloped email API.
Usage:
client := envloped.NewClient("ev_your_api_key")
resp, err := client.Emails.Send(&envloped.SendEmailRequest{
From: "hello@yourdomain.com",
To: []string{"user@example.com"},
Subject: "Hello from Envloped",
Html: "<p>Welcome!</p>",
// Attachments: []envloped.Attachment{{Filename: "f.txt", Content: base64.StdEncoding.EncodeToString(data)}},
})
Package envloped provides a Go client for the Envloped email API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnauthorized = errors.New("unauthorized") // ErrForbidden is returned when the request is not allowed (HTTP 403). // This typically means the domain is not registered or not verified. ErrForbidden = errors.New("forbidden") // ErrRateLimited is returned when usage limits have been exceeded (HTTP 429). ErrRateLimited = errors.New("rate limit exceeded") // ErrValidation is returned when the request body is invalid (HTTP 400). ErrValidation = errors.New("validation error") )
Sentinel errors for use with errors.Is().
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
// StatusCode is the HTTP status code returned by the API.
StatusCode int `json:"statusCode"`
// Message is the primary error message.
Message string `json:"error"`
// Details provides additional context about the error (present on 500 responses).
Details string `json:"details,omitempty"`
}
APIError represents a generic error response from the Envloped API.
type Attachment ¶ added in v1.1.0
type Attachment struct {
// Filename is the name of the attached file (e.g., "invoice.pdf"). Required.
Filename string `json:"filename"`
// Content is the base64-encoded content of the file. Required.
Content string `json:"content"`
// ContentType is the MIME type of the attachment (e.g., "application/pdf", "text/calendar").
// Optional — omitted if empty.
ContentType string `json:"contentType,omitempty"`
}
Attachment represents a file attachment to include with an email.
type Client ¶
type Client struct {
// Emails provides access to the email sending API.
Emails EmailsSvc
// contains filtered or unexported fields
}
Client handles communication with the Envloped API.
func NewClient ¶
NewClient creates a new Envloped API client with the given API key. The client defaults to the production API at https://api.envloped.com.
func (*Client) Ping ¶
func (c *Client) Ping() (*PingResponse, error)
Ping checks connectivity and API key validity. Returns a PingResponse on success or an error on failure.
func (*Client) PingWithContext ¶
func (c *Client) PingWithContext(ctx context.Context) (*PingResponse, error)
PingWithContext checks connectivity and API key validity using the given context.
func (*Client) WithBaseURL ¶
WithBaseURL sets a custom base URL for the API client. This is useful for testing or self-hosted deployments. Returns the client for method chaining.
type EmailUsage ¶
type EmailUsage struct {
DailyCount int `json:"dailyCount"`
MonthlyCount int `json:"monthlyCount"`
DailyLimit *int `json:"dailyLimit"` // nil means unlimited
MonthlyLimit int `json:"monthlyLimit"`
}
EmailUsage contains email usage counters and limits returned with rate limit errors.
type EmailsSvc ¶
type EmailsSvc interface {
// Send sends an email with the given parameters.
Send(params *SendEmailRequest) (*SendEmailResponse, error)
// SendWithContext sends an email using the provided context for cancellation and deadlines.
SendWithContext(ctx context.Context, params *SendEmailRequest) (*SendEmailResponse, error)
}
EmailsSvc defines the interface for the email sending service. This interface can be mocked in consumer tests.
type PingResponse ¶
PingResponse is the response from the Ping endpoint.
type RateLimitError ¶
type RateLimitError struct {
APIError
// Reason is a human-readable explanation of which limit was exceeded.
Reason string `json:"message,omitempty"`
// Usage contains the current usage counters and limits.
Usage *EmailUsage `json:"usage,omitempty"`
}
RateLimitError is returned when the API responds with HTTP 429. It embeds APIError and adds usage details.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
Error implements the error interface.
func (*RateLimitError) Is ¶
func (e *RateLimitError) Is(target error) bool
Is enables sentinel error matching via errors.Is().
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
Unwrap returns the underlying APIError for errors.Unwrap() support.
type SendEmailRequest ¶
type SendEmailRequest struct {
// From is the sender email address (e.g., "hello@yourdomain.com" or "My App <hello@yourdomain.com>").
// The domain must be verified in your Envloped dashboard.
From string `json:"from"`
// To is the list of recipient email addresses.
To []string `json:"to"`
// Subject is the email subject line.
Subject string `json:"subject"`
// Html is the HTML body of the email. At least one of Html or Text must be provided.
Html string `json:"html,omitempty"`
// Text is the plain text body of the email. At least one of Html or Text must be provided.
Text string `json:"text,omitempty"`
// Attachments is an optional list of file attachments. At most 10 attachments;
// combined decoded payload must not exceed 40 MB (validated here and by the API).
Attachments []Attachment `json:"attachments,omitempty"`
}
SendEmailRequest is the request body for sending an email.
See https://docs.envloped.com/api-reference/emails/send-email
type SendEmailResponse ¶
type SendEmailResponse struct {
// Success indicates whether the email was sent successfully.
Success bool `json:"success"`
// MessageId is the unique identifier for the sent email (SES Message ID).
MessageId string `json:"messageId"`
}
SendEmailResponse is the response from a successful email send.
type ValidationError ¶
type ValidationError struct {
APIError
}
ValidationError is returned when the API responds with HTTP 400. It embeds APIError for consistency.
func (*ValidationError) Is ¶
func (e *ValidationError) Is(target error) bool
Is enables sentinel error matching via errors.Is().
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
Unwrap returns the underlying APIError for errors.Unwrap() support.