mail

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mail is the service's domain: the message a caller hands to smtp.Send, its checks and limits, address hashing and the MIME it becomes. It knows nothing of accounts, queues or the platform.

Index

Constants

View Source
const (
	DefaultMaxBytes      = 25 << 20
	DefaultMaxRecipients = 100
)

Defaults of the limits.

Variables

View Source
var (
	ErrNoRecipient = errors.New("mail: no recipient")
	ErrNoSubject   = errors.New("mail: subject is empty")
	ErrNoBody      = errors.New("mail: text or html body is required")
	ErrAddress     = errors.New("mail: invalid address")
	ErrHeader      = errors.New("mail: header not allowed")
	ErrTooBig      = errors.New("mail: message exceeds the size limit")
	ErrAttachment  = errors.New("mail: invalid attachment")
)

Errors of Validate; every one is final: no retry changes the message.

View Source
var DefaultLimits = Limits{MaxBytes: DefaultMaxBytes, MaxRecipients: DefaultMaxRecipients}

DefaultLimits of a message: 25 MiB, 100 recipients.

Functions

func Build

func Build(m Message, from, id string) (*gomail.Msg, error)

Build is the message as MIME, with from as sender when the message names none and id as its Message-ID.

func Hash

func Hash(address string) string

Hash identifies an address without keeping it: sha256 of the lower-cased address part, hex.

func Hashes

func Hashes(addresses []string) []string

Hashes of every address, in order.

Types

type Attachment

type Attachment struct {
	Name        string `json:"name"                   schemapb:"description=File name"`
	ContentType string `json:"content_type,omitempty" schemapb:"description=MIME type, inferred from the name when empty"`
	Data        []byte `json:"data"                   schemapb:"description=Content, base64"`
}

Attachment is a file in the message; Data is base64 on the wire.

type Limits

type Limits struct {
	// MaxBytes bounds the sum of bodies and attachments.
	MaxBytes int64
	// MaxRecipients bounds to + cc + bcc.
	MaxRecipients int
}

Limits bound a message.

type Message

type Message struct {
	// Account names the installation's SMTP account; empty: the default
	// (or what the Route hook says).
	Account string `json:"account,omitempty" schemapb:"description=SMTP account of the installation, else the default"`
	// From overrides the account's default sender.
	From    string   `json:"from,omitempty"     schemapb:"description=Sender, else the account's default"`
	To      []string `json:"to"                 schemapb:"description=Recipients"`
	Cc      []string `json:"cc,omitempty"`
	Bcc     []string `json:"bcc,omitempty"`
	ReplyTo string   `json:"reply_to,omitempty"`
	Subject string   `json:"subject"`
	Text    string   `json:"text,omitempty"     schemapb:"description=Plain text body"`
	HTML    string   `json:"html,omitempty"     schemapb:"description=HTML body, an alternative of text when both are set"`
	// Headers: X-*, List-*, In-Reply-To, References, Precedence and the like.
	Headers     map[string]string `json:"headers,omitempty"     schemapb:"description=Extra headers: X-*, List-*"`
	Attachments []Attachment      `json:"attachments,omitempty"`
	// IdempotencyKey: two calls with the same key send one mail; empty:
	// the activity execution's key.
	IdempotencyKey string `json:"idempotency_key,omitempty" schemapb:"description=Same key: one delivery"`
}

Message is what a caller sends: a rendered mail. Addresses are RFC 5322 ("Name <user@host>" or "user@host").

func (Message) Recipients

func (m Message) Recipients() []string

Recipients are to, cc and bcc in order, as given.

func (Message) Size

func (m Message) Size() int64

Size is what the bodies and attachments take.

func (Message) Validate

func (m Message) Validate(limits Limits) error

Validate checks the message against the limits; its error is final.

Jump to

Keyboard shortcuts

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