message

package
v1.117.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const MaxFilenameBytes = 255

MaxFilenameBytes bounds a file's name CheckFilename takes: written into Content-Type and Content-Disposition, its every byte percent-encoded at worst, it keeps either line well within the 998 octets RFC 5322 allows one.

Variables

This section is empty.

Functions

func CheckFilename added in v1.117.0

func CheckFilename(filename string) error

CheckFilename refuses, as ErrValidationError, a name a file is not to be attached under: an empty one, "." or "..", one longer than MaxFilenameBytes or not UTF-8, and one with a control character, a format character (a bidirectional one, as in "invoice\u202efdp.exe", or one that shows as nothing, as a zero-width space), a line or paragraph separator -- each lets a name display as other than it is -- a quote, a backslash or a slash: a path's separators, and what Attachment would write encoded or escaped where mail clients read either differently. A name taken from someone else is checked before it is attached.

Types

type Body

type Body struct {
	Content     []byte
	ContentType string
	Headers     []*message_header.Header
	Parts       []*Body
	Subtype     string
}

func Attachment

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

Attachment is a part carrying the content, base64, as a file of the content type, named filename when one is given. A content type that is not one, or not given, is application/octet-stream, rather than written as it is: what follows a line break in it would be a header of its own; one with a parameter that does not parse, or that parses but cannot be written again, is kept without its parameters. The name is written as a parameter of Content-Type and of Content-Disposition, quoted where it needs to be, and encoded as RFC 2231 has it where it is not printable ASCII.

func Text added in v1.98.0

func Text(text string) *Body

Text is a text/plain body of the text, quoted-printable, so that a line is never longer than mail allows and a character outside ASCII arrives as it was written.

func (*Body) Validate

func (body *Body) Validate() error

Validate refuses a body that cannot be written: a multipart one without its subtype, a part without its content type, and a part whose headers would end their lines (ErrHeaderInjection).

type Message

type Message struct {
	From    *mail.Address
	To      []*mail.Address
	Cc      []*mail.Address
	Bcc     []*mail.Address
	Subject string
	Body    *Body
	ReplyTo []*mail.Address
	Domain  string
	Headers []*message_header.Header
	// Date is when the message is dated, in its own zone; the time it is written, if zero.
	Date time.Time
}

func New

func New(from *mail.Address, to []*mail.Address, subject string, body *Body, options ...message_config.Option) (*Message, error)

func (*Message) String

func (message *Message) String() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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