Documentation
¶
Overview ¶
Package email implements SMTP send and IMAP read for the email provider.
Index ¶
- Constants
- func EncodeMessageID(mailbox string, uidValidity, uid uint32) string
- func FormatLegacyMessageID(uidValidity, uid uint32) string
- func ParseLegacyMessageID(id string) (uidValidity, uid uint32, err error)
- func ResolveTLSMode(mode string, port int, implicitPorts ...int) string
- type AttachmentMeta
- type Client
- func (c *Client) Config() Config
- func (c *Client) Get(ctx context.Context, id string) (*Message, error)
- func (c *Client) HealthCheck(ctx context.Context) error
- func (c *Client) List(ctx context.Context, mailbox string, unseenOnly bool, limit int, cursor string) ([]MessageMeta, string, error)
- func (c *Client) ListRawEvents(ctx context.Context, cursor string) ([]map[string]any, string, error)
- func (c *Client) MarkSeen(ctx context.Context, id string, seen bool) error
- func (c *Client) Search(ctx context.Context, q SearchQuery) ([]MessageMeta, string, error)
- func (c *Client) Send(ctx context.Context, in SendInput) error
- type Config
- type Message
- type MessageMeta
- type MessageRef
- type SearchQuery
- type SendInput
Constants ¶
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
EncodeMessageID builds an opaque external message id (mailbox + uidvalidity + uid).
func FormatLegacyMessageID ¶ added in v0.99.0
FormatLegacyMessageID builds the legacy uidvalidity:uid form (tests / migration).
func ParseLegacyMessageID ¶ added in v0.99.0
ParseLegacyMessageID parses uidvalidity:uid.
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
GetClient returns an email client from YAML config. Returns nil, nil when username or hosts are not configured.
func (*Client) HealthCheck ¶ added in v0.99.0
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
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.
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.