email

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package email provides email sending functionality using SMTP.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotConfigured is returned when SMTP is not configured.
	ErrNotConfigured = errors.New("email: SMTP not configured")
	// ErrInvalidRecipient is returned when the recipient email is invalid.
	ErrInvalidRecipient = errors.New("email: invalid recipient email")
	// ErrSendFailed is returned when email sending fails.
	ErrSendFailed = errors.New("email: failed to send email")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host       string
	Port       int
	User       string
	Password   string
	From       string
	FromName   string
	TLS        bool
	SkipVerify bool
	Timeout    time.Duration
}

Config holds SMTP configuration.

type Logger

type Logger interface {
	Info(msg string, args ...any)
}

Logger is a simple logging interface.

type LoggingSender

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

LoggingSender wraps a sender and logs all email operations.

func NewLoggingSender

func NewLoggingSender(sender Sender, logger Logger) *LoggingSender

NewLoggingSender creates a new logging sender.

func (*LoggingSender) IsConfigured

func (s *LoggingSender) IsConfigured() bool

IsConfigured returns true if the underlying sender is configured.

func (*LoggingSender) Send

func (s *LoggingSender) Send(ctx context.Context, msg *Message) error

Send logs and sends the email.

func (*LoggingSender) SendTemplate

func (s *LoggingSender) SendTemplate(ctx context.Context, to string, template Template, data any) error

SendTemplate logs and sends a templated email.

type Message

type Message struct {
	To      []string
	Subject string
	Body    string
	IsHTML  bool
	ReplyTo string
	Headers map[string]string
}

Message represents an email message.

type NoOpSender

type NoOpSender struct{}

NoOpSender is a sender that does nothing (for development/testing).

func NewNoOpSender

func NewNoOpSender() *NoOpSender

NewNoOpSender creates a new no-op sender.

func (*NoOpSender) IsConfigured

func (s *NoOpSender) IsConfigured() bool

IsConfigured always returns true for no-op sender.

func (*NoOpSender) Send

func (s *NoOpSender) Send(_ context.Context, _ *Message) error

Send does nothing and returns nil.

func (*NoOpSender) SendTemplate

func (s *NoOpSender) SendTemplate(_ context.Context, _ string, _ Template, _ any) error

SendTemplate does nothing and returns nil.

type PasswordChangedData

type PasswordChangedData struct {
	UserName   string
	Email      string
	ChangedAt  string
	IPAddress  string
	AppName    string
	SupportURL string
}

PasswordChangedData holds data for the password changed notification.

type PasswordResetData

type PasswordResetData struct {
	UserName    string
	Email       string
	ResetURL    string
	ExpiresIn   string
	AppName     string
	IPAddress   string
	RequestedAt string
}

PasswordResetData holds data for the password reset template.

type SMTPSender

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

SMTPSender implements Sender using SMTP.

func NewSMTPSender

func NewSMTPSender(cfg Config) *SMTPSender

NewSMTPSender creates a new SMTP sender.

func (*SMTPSender) IsConfigured

func (s *SMTPSender) IsConfigured() bool

IsConfigured returns true if SMTP is properly configured.

func (*SMTPSender) Send

func (s *SMTPSender) Send(ctx context.Context, msg *Message) error

Send sends an email message.

func (*SMTPSender) SendTemplate

func (s *SMTPSender) SendTemplate(ctx context.Context, to string, template Template, data any) error

SendTemplate sends an email using a predefined template.

type Sender

type Sender interface {
	Send(ctx context.Context, msg *Message) error
	SendTemplate(ctx context.Context, to string, template Template, data any) error
	IsConfigured() bool
}

Sender defines the interface for sending emails.

type TeamInvitationData

type TeamInvitationData struct {
	InviterName   string
	TeamName      string
	InvitationURL string
	ExpiresIn     string
	AppName       string
}

TeamInvitationData holds data for the team invitation template.

type Template

type Template string

Template represents a predefined email template type.

const (
	// TemplateVerifyEmail is the email verification template.
	TemplateVerifyEmail Template = "verify_email"
	// TemplatePasswordReset is the password reset template.
	TemplatePasswordReset Template = "password_reset"
	// TemplatePasswordChanged is the password changed notification template.
	TemplatePasswordChanged Template = "password_changed"
	// TemplateWelcome is the welcome email template.
	TemplateWelcome Template = "welcome"
	// TemplateTeamInvitation is the team invitation template.
	TemplateTeamInvitation Template = "team_invitation"
)

type TemplateEngine

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

TemplateEngine handles email template rendering.

func NewTemplateEngine

func NewTemplateEngine() *TemplateEngine

NewTemplateEngine creates a new template engine with all predefined templates.

func (*TemplateEngine) Render

func (e *TemplateEngine) Render(tmpl Template, data any) (subject string, body string, err error)

Render renders a template with the given data.

type VerifyEmailData

type VerifyEmailData struct {
	UserName        string
	Email           string
	VerificationURL string
	ExpiresIn       string
	AppName         string
}

VerifyEmailData holds data for the email verification template.

type WelcomeData

type WelcomeData struct {
	UserName   string
	Email      string
	LoginURL   string
	AppName    string
	SupportURL string
}

WelcomeData holds data for the welcome email template.

Jump to

Keyboard shortcuts

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