email

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package email provides email sending functionality using the Resend API. It includes a Client interface for sending emails and a Tracker interface for tracking email requests.

Index

Constants

View Source
const (
	ResendAPIKeyEnv  = "RESEND_API_KEY"
	ResendBaseURLEnv = "RESEND_BASE_URL"
)

Environment variable names for Resend configuration

Variables

This section is empty.

Functions

func EmailParamsToJSON

func EmailParamsToJSON(from string, to []string, subject, text, html, replyTo string, cc, bcc []string, scheduledAt string, headers map[string]string, tags []map[string]string) string

EmailParamsToJSON converts the email parameters to a JSON string for logging

Types

type Client

type Client interface {
	Send(functionID string, req SendRequest) (*SendResponse, error)
}

Client is an interface for sending emails

type ConfigError

type ConfigError struct {
	Field string
}

ConfigError is returned when a required configuration is missing

func (*ConfigError) Error

func (e *ConfigError) Error() string

type DefaultClient

type DefaultClient struct {
	// contains filtered or unexported fields
}

DefaultClient is the default implementation of Client using Resend

func NewDefaultClient

func NewDefaultClient(envStore env.Store) *DefaultClient

NewDefaultClient creates a new email client

func (*DefaultClient) Send

func (c *DefaultClient) Send(functionID string, req SendRequest) (*SendResponse, error)

Send sends an email using Resend

type MemoryTracker

type MemoryTracker struct {
	// contains filtered or unexported fields
}

MemoryTracker is an in-memory implementation of Tracker

func NewMemoryTracker

func NewMemoryTracker() *MemoryTracker

NewMemoryTracker creates a new in-memory tracker

func (*MemoryTracker) Clear

func (m *MemoryTracker) Clear()

Clear removes all tracked requests

func (*MemoryTracker) Requests

func (m *MemoryTracker) Requests(executionID string) []store.EmailRequest

Requests returns all email requests for the specified executionID

func (*MemoryTracker) RequestsPaginated

func (m *MemoryTracker) RequestsPaginated(executionID string, limit, offset int) ([]store.EmailRequest, int64)

RequestsPaginated returns paginated email requests for the specified executionID

func (*MemoryTracker) Track

func (m *MemoryTracker) Track(executionID string, req TrackRequest)

Track records an email request

type SQLiteTracker

type SQLiteTracker struct {
	// contains filtered or unexported fields
}

SQLiteTracker is a SQLite-backed implementation of Tracker

func NewSQLiteTracker

func NewSQLiteTracker(db *sql.DB) *SQLiteTracker

NewSQLiteTracker creates a new SQLite-backed tracker

func (*SQLiteTracker) Requests

func (s *SQLiteTracker) Requests(executionID string) []store.EmailRequest

Requests returns all email requests for the specified executionID

func (*SQLiteTracker) RequestsPaginated

func (s *SQLiteTracker) RequestsPaginated(executionID string, limit, offset int) ([]store.EmailRequest, int64)

RequestsPaginated returns paginated email requests for the specified executionID

func (*SQLiteTracker) Track

func (s *SQLiteTracker) Track(executionID string, req TrackRequest)

Track records an email request

type SendRequest

type SendRequest struct {
	From        string
	To          []string
	Subject     string
	Text        string
	HTML        string
	ReplyTo     string
	Cc          []string
	Bcc         []string
	Headers     map[string]string
	Tags        []Tag
	ScheduledAt string
}

SendRequest represents a request to send an email

type SendResponse

type SendResponse struct {
	ID          string
	RequestJSON string
}

SendResponse represents the response from sending an email

type Tag

type Tag struct {
	Name  string
	Value string
}

Tag represents an email tag for categorization

type TrackRequest

type TrackRequest struct {
	From         string
	To           []string
	Subject      string
	HasText      bool
	HasHTML      bool
	RequestJSON  string
	ResponseJSON *string
	Status       store.EmailRequestStatus
	ErrorMessage *string
	EmailID      *string
	DurationMs   int64
}

TrackRequest contains the data needed to track an email request

type Tracker

type Tracker interface {
	Track(executionID string, req TrackRequest)
	Requests(executionID string) []store.EmailRequest
	RequestsPaginated(executionID string, limit, offset int) ([]store.EmailRequest, int64)
}

Tracker is an interface for tracking email requests executionID is used to isolate requests for each function execution

Jump to

Keyboard shortcuts

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