email

package
v1.0.0-dev.12 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidEmail = errors.New("invalid email address")

ErrInvalidEmail indicates an email address is not valid.

Functions

This section is empty.

Types

type Address

type Address string

Address is how househunt represents email addresses.

func ParseAddress

func ParseAddress(raw string) (Address, error)

ParseAddress parses the given string and checks if it's shaped like an email address. It returns an error if the input is not a valid email address. Note that this doesn't guarantee the email address actually exists, it only checks the format.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(text []byte) error

type LogSender

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

LogSender is a Sender that logs the email to the logger instead of sending it. Note that this is not meant for production use as it logs the email addresses and all email contents. Resulting in sensitive information being logged.

func NewLogSender

func NewLogSender(logger *slog.Logger) *LogSender

NewLogSender creates a new LogSender.

func (*LogSender) Send

func (s *LogSender) Send(_ context.Context, from, recipient Address, subject, body string) error

Send logs the email to the logger.

type MemorySender

type MemorySender struct {
	Emails []struct {
		From      Address
		Recipient Address
		Subject   string
		Body      string
	}
}

func NewMemorySender

func NewMemorySender() *MemorySender

func (*MemorySender) Send

func (s *MemorySender) Send(_ context.Context, from, recipient Address, subject, body string) error

type Renderer

type Renderer interface {
	Render(w io.Writer, name string, element TemplateElement, data any) error
}

Renderer is responsible for rendering email templates.

type Sender

type Sender interface {
	Send(ctx context.Context, from, recipient Address, subject, body string) error
}

Sender is responsible for actually sending an email.

type Service

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

Service provides the main functionality for sending emails.

func NewService

func NewService(renderer Renderer, sender Sender, cfg ServiceConfig) *Service

func (*Service) Send

func (s *Service) Send(ctx context.Context, name string, recipient Address, data any) error

type ServiceConfig

type ServiceConfig struct {
	From    Address
	BaseURL *url.URL
}

ServiceConfig is the configuration for the email service.

type TemplateElement

type TemplateElement string

TemplateElement is used by a renderer to identify the different parts of an email template.

const (
	ElementSubject TemplateElement = "subject"
	ElementBody    TemplateElement = "body"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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