mail

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSender        = errors.New("coyote/mail: the message has no From address")
	ErrNoRecipient     = errors.New("coyote/mail: the message has no recipients")
	ErrNoBody          = errors.New("coyote/mail: the message has neither a text nor an HTML body")
	ErrBadAddress      = errors.New("coyote/mail: unusable address")
	ErrHeaderInjection = errors.New("coyote/mail: a header value contains a line break")
	ErrNotConfigured   = errors.New("coyote/mail: no email backend is configured")
	ErrSendFailed      = errors.New("coyote/mail: the server refused the message")
	ErrTooLarge        = errors.New("coyote/mail: the message is larger than the limit")
)

Functions

func Encode

func Encode(m Message) ([]byte, error)

func FormatAddress

func FormatAddress(name, address string) string

func FormatAddressList

func FormatAddressList(addresses []netmail.Address) string

func ParseAddress

func ParseAddress(value string) (netmail.Address, error)

func ParseAddressList

func ParseAddressList(values []string) ([]netmail.Address, error)

Types

type Attachment

type Attachment struct {
	Filename string
	Type     string
	Content  []byte
}

func FileAttachment

func FileAttachment(path string) (Attachment, error)

func NewAttachment

func NewAttachment(filename, contentType string, content []byte) Attachment

func (Attachment) ContentType

func (a Attachment) ContentType() string

func (Attachment) Name

func (a Attachment) Name() string

func (Attachment) Validate

func (a Attachment) Validate() error

type ConsoleSender

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

func NewConsole

func NewConsole(w io.Writer) *ConsoleSender

func (*ConsoleSender) Send

func (c *ConsoleSender) Send(ctx context.Context, message Message) error

type Encoder

type Encoder struct {
	Now      func() time.Time
	Boundary func() string
	Domain   string
}

func NewEncoder

func NewEncoder() Encoder

func (Encoder) Encode

func (e Encoder) Encode(m Message) ([]byte, error)

type FileSender

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

func NewFile

func NewFile(dir string) *FileSender

func (*FileSender) Dir

func (f *FileSender) Dir() string

func (*FileSender) Send

func (f *FileSender) Send(ctx context.Context, message Message) error

type MemorySender

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

func NewMemory

func NewMemory() *MemorySender

func (*MemorySender) Clear

func (m *MemorySender) Clear()

func (*MemorySender) Count

func (m *MemorySender) Count() int

func (*MemorySender) Last

func (m *MemorySender) Last() (Message, bool)

func (*MemorySender) Raw

func (m *MemorySender) Raw() [][]byte

func (*MemorySender) Send

func (m *MemorySender) Send(ctx context.Context, message Message) error

func (*MemorySender) Sent

func (m *MemorySender) Sent() []Message

type Message

type Message struct {
	From        string
	To          []string
	CC          []string
	BCC         []string
	ReplyTo     string
	Subject     string
	Text        string
	HTML        string
	Headers     map[string]string
	Attachments []Attachment
	Date        time.Time
	MessageID   string
}

func (Message) Attach

func (m Message) Attach(attachments ...Attachment) Message

func (Message) HasBody

func (m Message) HasBody() bool

func (Message) Recipients

func (m Message) Recipients() []string

func (Message) Validate

func (m Message) Validate() error

func (Message) WithHeader

func (m Message) WithHeader(name, value string) Message

type SMTPOptions

type SMTPOptions struct {
	Host      string
	Port      int
	Username  string
	Password  string
	TLS       TLSMode
	From      string
	Timeout   time.Duration
	LocalName string
	TLSConfig *tls.Config
}

func (SMTPOptions) Validate

func (o SMTPOptions) Validate() error

type SMTPSender

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

func NewSMTP

func NewSMTP(options SMTPOptions) *SMTPSender

func (*SMTPSender) Addr

func (s *SMTPSender) Addr() string

func (*SMTPSender) Send

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

type Sender

type Sender interface {
	Send(ctx context.Context, message Message) error
}

func WithDefaultFrom

func WithDefaultFrom(inner Sender, from string) Sender

type TLSMode

type TLSMode string
const (
	TLSNone     TLSMode = "none"
	TLSStartTLS TLSMode = "starttls"
	TLSImplicit TLSMode = "tls"
)

Jump to

Keyboard shortcuts

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