email

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Folders

func Folders(acct EmailAccount) ([]string, error)

Folders returns a sorted list of mailbox names available on the server.

func FormatDryRun

func FormatDryRun(acct EmailAccount, opts SendOptions) string

FormatDryRun returns a human-readable representation of the email that would be sent, for use with --dry-run.

func SaveAttachments

func SaveAttachments(acct EmailAccount, folder string, uid uint32, dir string) ([]string, error)

SaveAttachments downloads and saves all attachments of a message to dir. It returns the list of file paths written.

func Send

func Send(acct EmailAccount, opts SendOptions) error

Send composes and sends an email via SMTP using the provided account configuration.

func ValidateAccountName

func ValidateAccountName(name string) error

Types

type AttachmentInfo

type AttachmentInfo struct {
	Filename string `json:"filename"`
	Size     int64  `json:"size"`
	MIMEType string `json:"mime_type"`
}

AttachmentInfo holds metadata about a message attachment (no content).

type Config

type Config struct {
	Default  string                  `json:"default"`
	Accounts map[string]EmailAccount `json:"accounts"`
}

func LoadFromEnv

func LoadFromEnv() (*Config, error)

func (*Config) AccountNames

func (c *Config) AccountNames() []string

func (*Config) Remove

func (c *Config) Remove(name string) error

func (*Config) Resolve

func (c *Config) Resolve(name string) (EmailAccount, error)

func (*Config) SetDefault

func (c *Config) SetDefault(name string) error

func (*Config) Upsert

func (c *Config) Upsert(name string, partial EmailAccount)

type EmailAccount

type EmailAccount struct {
	IMAPHost string `json:"imap_host,omitempty"`
	IMAPPort int    `json:"imap_port,omitempty"`
	IMAPTLS  string `json:"imap_tls,omitempty"`
	SMTPHost string `json:"smtp_host,omitempty"`
	SMTPPort int    `json:"smtp_port,omitempty"`
	SMTPTLS  string `json:"smtp_tls,omitempty"`
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	From     string `json:"from,omitempty"`
}

type Envelope

type Envelope struct {
	UID            uint32    `json:"uid"`
	From           string    `json:"from"`
	To             []string  `json:"to"`
	Subject        string    `json:"subject"`
	Date           time.Time `json:"date"`
	Flags          []string  `json:"flags"`
	HasAttachments bool      `json:"has_attachments"`
	Size           int64     `json:"size"`
}

Envelope holds metadata about an email message.

func List

func List(acct EmailAccount, opts ListOptions) ([]Envelope, error)

List returns envelope metadata for messages in the given folder, filtered by opts.

type ListOptions

type ListOptions struct {
	Folder  string
	Limit   int
	Unread  bool
	From    string
	Subject string
	Since   *time.Time
	Before  *time.Time
}

ListOptions controls which messages are returned by List.

type Message

type Message struct {
	Envelope
	TextBody    string           `json:"text_body,omitempty"`
	HTMLBody    string           `json:"html_body,omitempty"`
	Attachments []AttachmentInfo `json:"attachments,omitempty"`
}

Message is a fully-fetched email message including body and attachment metadata.

func Read

func Read(acct EmailAccount, folder string, uid uint32) (*Message, error)

Read fetches and parses a single message by UID.

type SendOptions

type SendOptions struct {
	To          []string
	Cc          []string
	Bcc         []string
	Subject     string
	Body        string
	HTML        bool
	Attachments []string // file paths
	From        string   // override sender
	ReplyTo     string
}

SendOptions holds the parameters for composing and sending an email.

Jump to

Keyboard shortcuts

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