email

package
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package email implements SMTP send and IMAP read for the email provider.

Index

Constants

View Source
const (
	ID = "email"

	UsernameKey          = "username"
	PasswordKey          = "password"
	SMTPHostKey          = "smtp_host"
	SMTPPortKey          = "smtp_port"
	SMTPTLSKey           = "smtp_tls"
	IMAPHostKey          = "imap_host"
	IMAPPortKey          = "imap_port"
	IMAPTLSKey           = "imap_tls"
	MailboxKey           = "mailbox"
	UnseenOnlyKey        = "unseen_only"
	MarkSeenAfterEmitKey = "mark_seen_after_emit"

	TLSModeTLS      = "tls"
	TLSModeSTARTTLS = "starttls"
)

Variables

This section is empty.

Functions

func EncodeMessageID added in v0.99.0

func EncodeMessageID(mailbox string, uidValidity, uid uint32) string

EncodeMessageID builds an opaque external message id (mailbox + uidvalidity + uid).

func FormatLegacyMessageID added in v0.99.0

func FormatLegacyMessageID(uidValidity, uid uint32) string

FormatLegacyMessageID builds the legacy uidvalidity:uid form (tests / migration).

func ParseLegacyMessageID added in v0.99.0

func ParseLegacyMessageID(id string) (uidValidity, uid uint32, err error)

ParseLegacyMessageID parses uidvalidity:uid.

func ResolveTLSMode added in v0.99.0

func ResolveTLSMode(mode string, port int, implicitPorts ...int) string

ResolveTLSMode returns tls|starttls. Empty mode uses port defaults (465/993 → tls, else starttls).

Types

type AttachmentMeta added in v0.99.0

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

AttachmentMeta describes an attachment without binary content.

type Client added in v0.99.0

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

Client is an SMTP/IMAP email client backed by YAML config.

func GetClient added in v0.99.0

func GetClient() (*Client, error)

GetClient returns an email client from YAML config. Returns nil, nil when username or hosts are not configured.

func NewClient added in v0.99.0

func NewClient(cfg Config) (*Client, error)

NewClient validates config and returns a client.

func (*Client) Config added in v0.99.0

func (c *Client) Config() Config

Config returns a copy of the client configuration.

func (*Client) Get added in v0.99.0

func (c *Client) Get(ctx context.Context, id string) (*Message, error)

Get fetches a single message by opaque id.

func (*Client) HealthCheck added in v0.99.0

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck verifies IMAP login and SMTP handshake/auth when configured.

func (*Client) List added in v0.99.0

func (c *Client) List(ctx context.Context, mailbox string, unseenOnly bool, limit int, cursor string) ([]MessageMeta, string, error)

List returns message metadata for a mailbox with optional unseen filter and cursor pagination.

func (*Client) ListRawEvents added in v0.99.0

func (c *Client) ListRawEvents(ctx context.Context, cursor string) ([]map[string]any, string, error)

ListRawEvents returns poller items (metadata maps) using configured mailbox/unseen defaults.

func (*Client) MarkSeen added in v0.99.0

func (c *Client) MarkSeen(ctx context.Context, id string, seen bool) error

MarkSeen sets or clears the \\Seen flag for a message id.

func (*Client) Search added in v0.99.0

func (c *Client) Search(ctx context.Context, q SearchQuery) ([]MessageMeta, string, error)

Search finds messages matching criteria.

func (*Client) Send added in v0.99.0

func (c *Client) Send(ctx context.Context, in SendInput) error

Send delivers a message via SMTP.

type Config

type Config struct {
	Username          string
	Password          string
	SMTPHost          string
	SMTPPort          int
	SMTPTLS           string
	IMAPHost          string
	IMAPPort          int
	IMAPTLS           string
	Mailbox           string
	UnseenOnly        bool
	MarkSeenAfterEmit bool
}

Config holds SMTP/IMAP settings for the email provider.

type Message added in v0.99.0

type Message struct {
	MessageMeta
	Text string `json:"text,omitzero"`
	HTML string `json:"html,omitzero"`
}

Message is a full message including body text/html.

type MessageMeta added in v0.99.0

type MessageMeta struct {
	ID          string           `json:"id"`
	UID         uint32           `json:"uid"`
	UIDValidity uint32           `json:"uidvalidity"`
	Mailbox     string           `json:"mailbox"`
	From        []string         `json:"from,omitzero"`
	To          []string         `json:"to,omitzero"`
	Cc          []string         `json:"cc,omitzero"`
	Subject     string           `json:"subject,omitzero"`
	Date        time.Time        `json:"date,omitzero"`
	MessageID   string           `json:"message_id,omitzero"`
	Seen        bool             `json:"seen"`
	Attachments []AttachmentMeta `json:"attachments,omitzero"`
}

MessageMeta is email metadata returned by list/search/poller.

type MessageRef added in v0.99.0

type MessageRef struct {
	Mailbox     string `json:"m"`
	UIDValidity uint32 `json:"v"`
	UID         uint32 `json:"u"`
}

MessageRef identifies a message inside a mailbox.

func DecodeMessageID added in v0.99.0

func DecodeMessageID(id string) (MessageRef, error)

DecodeMessageID parses an opaque id, or a legacy uidvalidity:uid form.

type SearchQuery added in v0.99.0

type SearchQuery struct {
	Mailbox string
	From    string
	To      string
	Subject string
	Since   *time.Time
	Before  *time.Time
	Unseen  *bool
	Limit   int
	Cursor  string
}

SearchQuery holds IMAP search filters and pagination.

type SendInput added in v0.99.0

type SendInput struct {
	To       []string
	Cc       []string
	Bcc      []string
	Subject  string
	Text     string
	HTML     string
	FromName string
}

SendInput holds outbound message fields.

Jump to

Keyboard shortcuts

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