mail

package
v0.9.16 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDriver

func RegisterDriver(name string, factory func() (Mailer, error))

RegisterDriver allows drivers to register themselves

func SetTemplatePath added in v0.8.0

func SetTemplatePath(path string)

SetTemplatePath configures the directory for email templates

Types

type Address

type Address struct {
	Email string
	Name  string
}

Address represents an email address

func NewAddress added in v0.9.2

func NewAddress(email string, name ...string) (Address, error)

NewAddress creates and validates an email address. Returns an error if the email format is invalid.

func (Address) String

func (a Address) String() string

String returns the formatted email address

type Attachment

type Attachment struct {
	Name        string
	Data        []byte
	ContentType string
}

Attachment represents an email attachment

type MailConfig added in v0.9.5

type MailConfig struct {
	// Driver is the mail driver to use (e.g. "log", "postmark", "mailgun").
	Driver string
}

MailConfig holds configuration for creating a mailer.

type MailFailed added in v0.8.0

type MailFailed struct {
	Context    context.Context
	To         []string
	Subject    string
	Channel    string
	Error      string
	DurationMs int64
	TraceID    string
	SpanID     string
	ParentID   string
}

MailFailed is dispatched when an email fails to send

func (*MailFailed) Name added in v0.8.0

func (e *MailFailed) Name() string

Name returns the event name

type MailSent added in v0.8.0

type MailSent struct {
	Context    context.Context
	To         []string
	Subject    string
	Channel    string
	DurationMs int64
	TraceID    string
	SpanID     string
	ParentID   string
}

MailSent is dispatched after an email is sent successfully

func (*MailSent) Name added in v0.8.0

func (e *MailSent) Name() string

Name returns the event name

type Mailer

type Mailer interface {
	Send(ctx context.Context, msg *Message) error
}

Mailer interface that all mail drivers must implement

func NewMailer added in v0.9.5

func NewMailer(config MailConfig) (Mailer, error)

NewMailer creates a new Mailer from the given configuration. Drivers must be registered via RegisterDriver before calling this function.

type Manager

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

Manager manages multiple mail channels

func NewManager

func NewManager() *Manager

NewManager creates a new mail manager

func (*Manager) Broadcast

func (m *Manager) Broadcast(ctx context.Context, channels []string, msg *Message) error

Broadcast sends a message to multiple channels

func (*Manager) Channel

func (m *Manager) Channel(name string) Mailer

Channel gets or creates a mail channel

func (*Manager) ClearChannels

func (m *Manager) ClearChannels()

ClearChannels removes all channels

func (*Manager) GetChannels

func (m *Manager) GetChannels() []string

GetChannels returns all channel names

func (*Manager) HasChannel

func (m *Manager) HasChannel(name string) bool

HasChannel checks if a channel exists

func (*Manager) RemoveChannel

func (m *Manager) RemoveChannel(name string)

RemoveChannel removes a channel

func (*Manager) Send

func (m *Manager) Send(ctx context.Context, channel string, msg *Message) error

Send sends a message using a specific channel

func (*Manager) SetChannel

func (m *Manager) SetChannel(name string, mailer Mailer)

SetChannel sets a specific mailer for a channel

func (*Manager) SetEventDispatcher added in v0.9.11

func (m *Manager) SetEventDispatcher(fn func(event interface{}) error)

SetEventDispatcher sets the function used to dispatch events.

type Message

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

Message represents an email message

func NewMessage

func NewMessage() *Message

NewMessage creates a new email message

func (*Message) AttachData

func (m *Message) AttachData(data []byte, name, contentType string) *Message

AttachData attaches data from memory

func (*Message) AttachFile

func (m *Message) AttachFile(path string) (*Message, error)

AttachFile attaches a file from the filesystem. Returns an error if the file cannot be read or the path contains traversal sequences.

func (*Message) BCC

func (m *Message) BCC(email string, name ...string) *Message

BCC adds a BCC recipient

func (*Message) Body

func (m *Message) Body(body string) *Message

Body sets the plain text body (convenience method)

func (*Message) CC

func (m *Message) CC(email string, name ...string) *Message

CC adds a CC recipient

func (*Message) From

func (m *Message) From(email string, name ...string) *Message

From sets the sender address

func (*Message) GetAttachments

func (m *Message) GetAttachments() []Attachment

GetAttachments returns the attachments

func (*Message) GetBCC

func (m *Message) GetBCC() []Address

GetBCC returns the BCC addresses

func (*Message) GetCC

func (m *Message) GetCC() []Address

GetCC returns the CC addresses

func (*Message) GetFrom

func (m *Message) GetFrom() Address

GetFrom returns the from address

func (*Message) GetHTMLBody

func (m *Message) GetHTMLBody() string

GetHTMLBody returns the HTML body

func (*Message) GetHeaders

func (m *Message) GetHeaders() map[string]string

GetHeaders returns the custom headers

func (*Message) GetPriority

func (m *Message) GetPriority() Priority

GetPriority returns the priority

func (*Message) GetReplyTo

func (m *Message) GetReplyTo() []Address

GetReplyTo returns the reply-to addresses

func (*Message) GetSubject

func (m *Message) GetSubject() string

GetSubject returns the subject

func (*Message) GetTextBody

func (m *Message) GetTextBody() string

GetTextBody returns the plain text body

func (*Message) GetTo

func (m *Message) GetTo() []Address

GetTo returns the to addresses

func (*Message) HTMLBody

func (m *Message) HTMLBody(body string) *Message

HTMLBody sets the HTML body

func (*Message) Header

func (m *Message) Header(key, value string) *Message

Header adds a custom header

func (*Message) Priority

func (m *Message) Priority(priority Priority) *Message

Priority sets the email priority

func (*Message) ReplyTo

func (m *Message) ReplyTo(email string, name ...string) *Message

ReplyTo sets the reply-to address

func (*Message) Subject

func (m *Message) Subject(subject string) *Message

Subject sets the email subject

func (*Message) Template

func (m *Message) Template(name string, data interface{}) (*Message, error)

Template renders a template with data and sets it as HTML body. Returns an error if the template name is invalid or template processing fails.

func (*Message) TextBody

func (m *Message) TextBody(body string) *Message

TextBody sets the plain text body

func (*Message) To

func (m *Message) To(email string, name ...string) *Message

To adds a recipient

type Priority

type Priority int

Priority levels for emails

const (
	LowPriority Priority = iota
	NormalPriority
	HighPriority
)

Directories

Path Synopsis
Package alldrivers imports all mail drivers to register them Import this package with _ to ensure all drivers are registered
Package alldrivers imports all mail drivers to register them Import this package with _ to ensure all drivers are registered

Jump to

Keyboard shortcuts

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