Documentation
¶
Overview ¶
Package mail is the service's domain: the message a caller hands to courier.SendMail, its checks and limits, address hashing and the MIME it becomes. It knows nothing of accounts, queues or the platform.
Index ¶
Constants ¶
const ( DefaultMaxBytes = 25 << 20 DefaultMaxRecipients = 100 )
Defaults of the limits.
Variables ¶
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.
var DefaultLimits = Limits{MaxBytes: DefaultMaxBytes, MaxRecipients: DefaultMaxRecipients}
DefaultLimits of a message: 25 MiB, 100 recipients.
Functions ¶
func Build ¶
Build is the message as MIME, with from as sender when the message names none and id as its Message-ID.
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 {
// Channel names the installation's mail channel; empty: the default.
Channel string `json:"channel,omitempty" schemapb:"description=Mail channel of the installation, else the default"`
// From overrides the channel's default sender.
From string `json:"from,omitempty" schemapb:"description=Sender, else the channel'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"`
}
Message is what a caller sends: a rendered mail. Addresses are RFC 5322 ("Name <user@host>" or "user@host").
func (Message) Recipients ¶
Recipients are to, cc and bcc in order, as given.