apistockdocs
v0.4 GitHub apistock.dev
Technical/Module packages

modules/mail/resend

import "apistock.dev/modules/mail/resend"Source on GitHub

Package resend sends email with Resend (https://resend.com) through its HTTP API (ADR-0025, ADR-0037).

sender, err := resend.New(cfg.ResendAPIKey)

The API key is a secret from the environment (RESEND_API_KEY). Sender names and addresses are chosen per message; apps fill them from runtime settings with mail.WithDefaults.

Refusals that retrying can't fix (invalid messages, unverified sender domains) wrap mail.ErrRejected. Rate limits, outages and an invalid API key (fixable by an operator) are temporary. Each message's idempotency key is sent as Resend's Idempotency-Key, so a retried job never sends twice.

Stability: pre-1.0 (ADR-0015).

Constants#

const DefaultBaseURL, …#

go
const (
	DefaultBaseURL = "https://api.resend.com"
	DefaultTimeout = 30 * time.Second
)

Defaults.

Types#

type Option#

go
type Option interface {
	// contains filtered or unexported methods
}

An Option configures New.

func WithBaseURL#

go
func WithBaseURL(u string) Option

WithBaseURL sets the API base URL, for tests. Default: DefaultBaseURL.

func WithHTTPClient#

go
func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client, for example one with a proxy. Its own timeout applies instead of WithTimeout.

func WithTimeout#

go
func WithTimeout(d time.Duration) Option

WithTimeout bounds each API request. Default: DefaultTimeout.

type Sender#

go
type Sender struct {
	// contains filtered or unexported fields
}

Sender delivers email through the Resend API. It is safe for concurrent use.

func New#

go
func New(apiKey config.Secret, opts ...Option) (*Sender, error)

New returns a sender using apiKey, a Resend API key such as "re_123…".

func (*Sender) Send#

go
func (s *Sender) Send(ctx context.Context, m mail.Message) error

Send delivers m.

v0.4
esc
↑↓ move↵ openesc close