resend

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 12 Imported by: 0

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

View Source
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.

View Source
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

type APIError struct {
	Status  int
	Name    string
	Message string
}

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.

func (*APIError) Error

func (e *APIError) Error() string

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 New

func New(cfg Config, log *slog.Logger) *Sender

func NewWithTemplates

func NewWithTemplates(cfg Config, tpl mailtpl.Templates, log *slog.Logger) (*Sender, error)

NewWithTemplates builds a Sender with a custom copy set (shared with the other email adapters through mailtpl). A parse failure fails construction.

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, to, subject, body string) error

func (*Sender) SendEmailVerification

func (s *Sender) SendEmailVerification(ctx context.Context, to, link string) error

func (*Sender) SendInvite

func (s *Sender) SendInvite(ctx context.Context, to, workspaceName, invitationID string) error

func (*Sender) SendLoginCode

func (s *Sender) SendLoginCode(ctx context.Context, to, code string) error

func (*Sender) SendPasswordReset

func (s *Sender) SendPasswordReset(ctx context.Context, to, link string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL