mailer

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingConfig        = errors.New("missing required configuration")
	ErrTemplateNotFound     = errors.New("template file not found")
	ErrTemplateParseFailed  = errors.New("failed to parse template")
	ErrTemplateMissingVars  = errors.New("template missing required variables")
	ErrSMTPConnectionFailed = errors.New("failed to connect to SMTP server")
	ErrInvalidEmail         = errors.New("invalid email address")
	ErrSendFailed           = errors.New("failed to send email")
)
View Source
var (
	ErrEmptyEmailAddress              = errors.New("empty email address")
	ErrInvalidEmailAddressCharacters  = errors.New("email address contains invalid characters")
	ErrTemplateDoesNotUseAllVariables = errors.New("template does not use all variables")
)

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration converts a time.Duration to a human-readable string Examples: "30 minutes", "1 hour", "2 days"

func ValidateEmail

func ValidateEmail(email string) error

ValidateEmail checks if an email address is valid

func ValidateMagicLinkTemplate

func ValidateMagicLinkTemplate(tmpl *template.Template) error

ValidateMagicLinkTemplate validates that a template contains all required variables

Types

type Client

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

Client is the mailer client

func (c *Client) SendMagicLink(ctx context.Context, email Email, magicLinkURL string, expiresIn time.Duration) error

SendMagicLink sends a magic link email to the specified recipient

func (*Client) TestConnection

func (c *Client) TestConnection(ctx context.Context) error

TestConnection tests the SMTP connection

type Config

type Config struct {
	// SMTP Configuration
	SMTPHost     string // SMTP server hostname
	SMTPPort     int    // SMTP server port (typically 587)
	SMTPUsername string // SMTP authentication username
	SMTPPassword string // SMTP authentication password

	// Sender Information
	FromEmail string // Sender email address
	FromName  string // Sender display name

	// Application Information
	AppName string // Application name for templates

	// Template Configuration
	MagicLinkTemplatePath string // Path to magic link HTML template file
}

Config holds the configuration for the mailer client

type Email

type Email struct {
	To  string   // Recipient email address
	CC  []string // CC recipients
	BCC []string // BCC recipients
}

Email represents an email to be sent

type Mailer

type Mailer interface {
	SendMagicLink(ctx context.Context, email Email, magicLinkURL string, expiresIn time.Duration) error
	TestConnection(ctx context.Context) error
}

func New

func New(config Config) (Mailer, error)

Jump to

Keyboard shortcuts

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