mail

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package mail defines immutable outbound messages and a replaceable delivery boundary. Transport implementations live in subpackages.

Index

Constants

View Source
const (
	// MaximumRecipients bounds one SMTP transaction and its To header.
	MaximumRecipients = 100
	// MaximumHeaderBytes is the RFC 5322 hard limit for one header line,
	// excluding its terminating CRLF.
	MaximumHeaderBytes = 998
	// MaximumBodyBytes bounds the combined unencoded text and HTML bodies.
	MaximumBodyBytes = 4 << 20
)

Variables

View Source
var ErrInvalidMessage = errors.New("mail: invalid message")

Functions

This section is empty.

Types

type Message

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

Message is an immutable, validated email message.

func NewMessage

func NewMessage(options MessageOptions) (Message, error)

NewMessage validates and snapshots an outbound message. At least one of Text or HTML is required; supplying both emits multipart/alternative.

func (Message) Date

func (message Message) Date() time.Time

func (Message) From

func (message Message) From() netmail.Address

From returns a copy of the envelope sender and From header address.

func (Message) HTML

func (message Message) HTML() string

func (Message) ReplyTo

func (message Message) ReplyTo() (netmail.Address, bool)

ReplyTo returns the optional Reply-To address.

func (Message) Subject

func (message Message) Subject() string

func (Message) Text

func (message Message) Text() string

func (Message) To

func (message Message) To() []netmail.Address

To returns a copy of the envelope recipients and To header addresses.

func (Message) WriteRFC5322

func (message Message) WriteRFC5322(writer io.Writer) error

WriteRFC5322 writes a deterministic RFC 5322 message using CRLF line endings and quoted-printable UTF-8 bodies. It does not perform SMTP dot stuffing; SMTP transports apply that at the DATA boundary.

type MessageError

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

MessageError identifies a bad field without including submitted content.

func (*MessageError) Error

func (err *MessageError) Error() string

func (*MessageError) Field

func (err *MessageError) Field() string

func (*MessageError) Unwrap

func (err *MessageError) Unwrap() error

type MessageOptions

type MessageOptions struct {
	From    netmail.Address
	To      []netmail.Address
	ReplyTo *netmail.Address
	Subject string
	Text    string
	HTML    string
	// Date defaults to the construction time. Supplying it is useful for
	// deterministic fixtures and messages restored from an outbox.
	Date time.Time
}

MessageOptions is consumed by NewMessage. NewMessage copies all values, so later changes to this structure or its To slice cannot alter the Message.

type Sender

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

Sender is the complete outbound delivery seam. Applications can replace an SMTP sender with an API transport, test double, or transactional outbox.

Directories

Path Synopsis
Package smtp delivers GoForge mail messages through SMTP.
Package smtp delivers GoForge mail messages through SMTP.

Jump to

Keyboard shortcuts

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