Documentation
¶
Overview ¶
Package resend sends email through the Resend HTTP API (https://api.resend.com). It exists next to the SMTP adapter because the two channels fail differently in the field (shuijing field report, 2026-10-25): HTTP sidesteps outbound SMTP port blocks (25/465/587 are commonly firewalled on cloud/home networks), returns structured error codes (APIError.Name distinguishes "key invalid" from "recipient refused"), and is the prerequisite for the email.* webhook event family.
It speaks the REST API directly with net/http instead of pulling the resend-go SDK: the send path is one endpoint and one JSON shape, and the framework does not take single-use dependencies for 30 lines of calls (same ruling as webx.SvixVerify). Note the SDK gap this avoids too: Go's resend-go v2 has no Receiving API — consumers that need inbound forwarding read GET /emails/receiving/{id} as raw REST either way.
Index ¶
- Constants
- type APIError
- type Config
- type Sender
- func (s *Sender) Send(ctx context.Context, to, subject, body string) error
- func (s *Sender) SendEmailVerification(ctx context.Context, to, link string) error
- func (s *Sender) SendInvite(ctx context.Context, to, workspaceName, invitationID string) error
- func (s *Sender) SendLoginCode(ctx context.Context, to, code string) error
- func (s *Sender) SendPasswordReset(ctx context.Context, to, link string) error
Constants ¶
const DefaultEndpoint = "https://api.resend.com"
DefaultEndpoint is the Resend API root. Config.Endpoint overrides it — that is how the hermetic tests point the sender at an httptest server.
const DefaultSendTimeout = 30 * time.Second
DefaultSendTimeout mirrors the SMTP adapter's cap. See the Sender doc comment for the context contract.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is a non-2xx Resend response. Name is the API's machine-readable error identifier (missing_api_key, invalid_from, validation_failure, rate_limit_exceeded, application_error …) — the reason to prefer this channel over SMTP, whose failures are free-form relay text.
type Config ¶
type Config struct {
APIKey string
From string
// Endpoint defaults to DefaultEndpoint. Test seam, not a product knob.
Endpoint string
// HTTPClient overrides the transport (nil = a default client). The
// per-send deadline comes from SendTimeout via ctx, so a client-level
// Timeout is unnecessary.
HTTPClient *http.Client
// SendTimeout caps each send (zero = DefaultSendTimeout).
SendTimeout time.Duration
}
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender sends templated email through the Resend HTTP API. Same context contract as the SMTP adapter: every send method DETACHES from the caller's cancellation/deadline (an HTTP request timeout must not kill an in-flight login-code send) and keeps only the ctx values, under its own timeout (Config.SendTimeout, default 30s).
func NewWithTemplates ¶
NewWithTemplates builds a Sender with a custom copy set (shared with the other email adapters through mailtpl). A parse failure fails construction.