email

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package email provides test helpers for constructing raw RFC 2822 email messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertStringSliceEqual

func AssertStringSliceEqual(t *testing.T, got, want []string, label string)

AssertStringSliceEqual compares two string slices with a descriptive label.

func MakeRaw

func MakeRaw(opts Options) []byte

MakeRaw constructs an RFC 2822 compliant raw message with correct \r\n line endings.

Types

type Attachment

type Attachment struct {
	Filename    string
	ContentType string
	Data        []byte // raw bytes; will be base64-encoded
}

Attachment represents a MIME attachment for the builder.

type MessageBuilder

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

MessageBuilder constructs MIME messages with a fluent API. By default, messages use \n line endings matching Go raw string literals.

func NewMessage

func NewMessage() *MessageBuilder

NewMessage creates a MessageBuilder with sensible defaults.

func (*MessageBuilder) Bcc

Bcc sets the Bcc header.

func (*MessageBuilder) Body

func (b *MessageBuilder) Body(v string) *MessageBuilder

Body sets the message body text.

func (*MessageBuilder) Boundary

func (b *MessageBuilder) Boundary(v string) *MessageBuilder

Boundary sets the multipart boundary string.

func (*MessageBuilder) Bytes

func (b *MessageBuilder) Bytes() []byte

Bytes builds the complete MIME message.

func (*MessageBuilder) CRLF

func (b *MessageBuilder) CRLF() *MessageBuilder

CRLF switches to \r\n line endings (RFC 2822 compliant).

func (*MessageBuilder) Cc

Cc sets the Cc header.

func (*MessageBuilder) ContentType

func (b *MessageBuilder) ContentType(v string) *MessageBuilder

ContentType overrides the Content-Type header (for non-multipart messages).

func (*MessageBuilder) Date

func (b *MessageBuilder) Date(v string) *MessageBuilder

Date sets the Date header.

func (*MessageBuilder) From

func (b *MessageBuilder) From(v string) *MessageBuilder

From sets the From header.

func (*MessageBuilder) Header

func (b *MessageBuilder) Header(key, value string) *MessageBuilder

Header sets an arbitrary header. If the key already exists, its value is overwritten (last-write-wins); otherwise the header is appended.

func (*MessageBuilder) HeaderAppend

func (b *MessageBuilder) HeaderAppend(key, value string) *MessageBuilder

HeaderAppend adds a header without deduplication, allowing multiple lines with the same key (e.g., multiple Received headers).

func (*MessageBuilder) NoSubject

func (b *MessageBuilder) NoSubject() *MessageBuilder

NoSubject omits the Subject header from the output.

func (*MessageBuilder) Subject

func (b *MessageBuilder) Subject(v string) *MessageBuilder

Subject sets the Subject header. Use NoSubject() to omit it entirely.

func (*MessageBuilder) To

To sets the To header.

func (*MessageBuilder) WithAttachment

func (b *MessageBuilder) WithAttachment(filename, contentType string, data []byte) *MessageBuilder

WithAttachment adds an attachment to the message.

type Options

type Options struct {
	From        string
	To          string
	Subject     string
	ContentType string
	Body        string
	Headers     map[string]string
}

Options configures a raw RFC 2822 email message for testing.

Jump to

Keyboard shortcuts

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