smtp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package smtp provides SMTP client for sending emails.

Index

Constants

This section is empty.

Variables

View Source
var ErrPoolClosed = errors.New("pool is closed")

ErrPoolClosed is returned when Get is called on a closed pool.

View Source
var ErrXOAuth2Challenge = errors.New("unexpected XOAUTH2 server challenge")

ErrXOAuth2Challenge indicates an unexpected server challenge during XOAUTH2.

Functions

This section is empty.

Types

type Client

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

Client wraps SMTP operations with rate limiting.

func (*Client) AccountID

func (c *Client) AccountID() string

AccountID returns the account ID.

func (*Client) Email

func (c *Client) Email() string

Email returns the account email.

func (*Client) RateLimitInfo

func (c *Client) RateLimitInfo() (int, int, time.Time)

RateLimitInfo returns current rate limit state.

func (*Client) Send

func (c *Client) Send(ctx context.Context, req *SendRequest) error

Send sends an email.

type Operations

type Operations interface {
	Send(ctx context.Context, accountID string, req *SendRequest) error
	AccountEmail(accountID string) (string, error)
	DefaultAccountID() string
}

Operations defines the SMTP operations interface. Tool handlers accept this interface instead of concrete *Pool, enabling mock injection for unit tests.

type Pool

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

Pool manages SMTP clients for multiple accounts.

func NewPool

func NewPool(cfg *config.Config) *Pool

NewPool creates a new SMTP client pool.

func (*Pool) AccountEmail

func (p *Pool) AccountEmail(accountID string) (string, error)

AccountEmail returns the email address for the given account.

func (*Pool) Close

func (p *Pool) Close()

Close rejects new operations. SMTP connections are short-lived (connect per Send), so there are no persistent connections to drain.

func (*Pool) DefaultAccountID

func (p *Pool) DefaultAccountID() string

DefaultAccountID returns the configured default account ID.

func (*Pool) Get

func (p *Pool) Get(accountID string) (*Client, error)

Get returns an SMTP client for the given account. Unlike IMAP Pool.Get(), this method does NOT need to release the mutex during client creation because SMTP clients are lightweight structs — no network I/O happens here. The actual TCP+TLS connection is deferred to Send() via DialAndSend(). Holding the lock for the duration is safe and correct. Returns ErrPoolClosed if the pool is shutting down.

func (*Pool) Send

func (p *Pool) Send(ctx context.Context, accountID string, req *SendRequest) error

Send sends an email for the given account.

type SendAttachment

type SendAttachment struct {
	Path     string // absolute file path (file-based)
	Filename string // display name
	Data     []byte // raw content (in-memory, e.g. from IMAP fetch)
}

SendAttachment represents a file attachment for sending. Set Path for file-based attachments (email_send), or Data for in-memory attachments (email_forward). If both are set, Data takes precedence.

type SendRequest

type SendRequest struct {
	To          []string
	CC          []string
	BCC         []string
	Subject     string
	Body        string
	IsHTML      bool
	ReplyTo     string
	InReplyTo   string
	References  []string
	Attachments []SendAttachment
}

SendRequest contains the parameters for sending an email.

Jump to

Keyboard shortcuts

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