mail

package
v0.1.0-preview.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package mail provides immutable, bounded MIME messages and a transport- neutral sender contract.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttachmentSpec

type AttachmentSpec struct {
	Filename    string
	ContentType string
	Data        []byte
}

AttachmentSpec describes one ordinary MIME attachment.

type Message

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

Message is an immutable serialized MIME message plus its SMTP envelope.

Example
message, err := NewMessage(MessageSpec{
	ID:       "order-41@example.com",
	Date:     mailTestDate,
	From:     "Orders <orders@example.com>",
	To:       []string{"customer@example.com"},
	Subject:  "Order 41 is ready",
	TextBody: "Your order is ready.",
})
if err != nil {
	panic(err)
}
fmt.Println(message.ID(), message.Recipients())
Output:
order-41@example.com [customer@example.com]

func NewMessage

func NewMessage(spec MessageSpec) (Message, error)

NewMessage validates, copies, and deterministically serializes one message.

func (Message) Bytes

func (message Message) Bytes() []byte

Bytes returns a defensive copy of the complete MIME message.

func (Message) EnvelopeFrom

func (message Message) EnvelopeFrom() string

EnvelopeFrom returns the normalized SMTP envelope sender.

func (Message) ID

func (message Message) ID() string

ID returns the caller-owned Message-ID without angle brackets.

func (Message) Recipients

func (message Message) Recipients() []string

Recipients returns de-duplicated To, Cc, and Bcc envelope recipients in that stable order.

type MessageSpec

type MessageSpec struct {
	ID          string
	Date        time.Time
	From        string
	To          []string
	Cc          []string
	Bcc         []string
	ReplyTo     string
	Subject     string
	TextBody    string
	HTMLBody    string
	Attachments []AttachmentSpec
}

MessageSpec is the inspectable input to NewMessage. Date and ID are caller-owned so serialization has no hidden clock, hostname, or randomness.

type Sender

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

Sender delivers one immutable message. Implementations own transport security, cancellation, retry, and observation policy.

Directories

Path Synopsis
Package mailtest provides an instance-owned, bounded mail sender for tests and local reference applications.
Package mailtest provides an instance-owned, bounded mail sender for tests and local reference applications.

Jump to

Keyboard shortcuts

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