mail

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 9 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 Reinitialize

func Reinitialize() error

Reinitialize reinitializes the mail driver (useful after config changes)

func ReinitializeWithDriver

func ReinitializeWithDriver(driver string) error

ReinitializeWithDriver reinitializes with a specific driver

func Send

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

Send sends an email using the default mailer

func SetDefaultMailer

func SetDefaultMailer(mailer Mailer)

SetDefaultMailer sets the default mailer

Types

type Address

type Address struct {
	Email string
	Name  string
}

Address represents an email address

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 Mailer

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

Mailer interface that all mail drivers must implement

func GetDefaultMailer

func GetDefaultMailer() Mailer

GetDefaultMailer returns the default mailer

type Manager

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

Manager manages multiple mail channels

func GetManager

func GetManager() *Manager

GetManager returns the default manager instance

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

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

AttachFile attaches a file from the filesystem

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) Send

func (m *Message) Send() error

Send sends the message using the default mailer

func (*Message) SendWithContext

func (m *Message) SendWithContext(ctx context.Context) error

SendWithContext sends the message using the default mailer with context

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

Template renders a template with data and sets it as HTML body

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