/** * @module * SMTP connection pool with optional rate limiting. * * @example * ```ts * import { SMTPPool } from "sently/pool"; * import { NodeAdapter } from "sently/adapters/node"; * * const pool = new SMTPPool({ * host: "smtp.example.com", * auth: { user: "you@example.com", pass: "secret" }, * adapter: new NodeAdapter(), * pool: true, * maxConnections: 5, * }); * * await pool.send({ * from: "you@example.com", * to: "recipient@example.com", * subject: "Hello", * text: "Pooled send", * }); * ``` */ import type { MailOptions, PoolConfig, SendResult, SMTPConfig, SocketAdapter, Transport, VerifyResult } from "../core/types.js"; /** Options for {@link SMTPPool}. */ export interface SMTPPoolOptions { /** Factory for a new socket adapter per pooled connection. */ createAdapter?: () => Promise | SocketAdapter; /** Injectable clock for rate limiting (testing). */ now?: () => number; } /** * SMTP connection pool with optional rate limiting. */ export declare class SMTPPool implements Transport { /** Resolved SMTP and pool configuration. */ private readonly config; /** Maximum simultaneous pooled connections. */ private readonly maxConnections; /** Maximum messages per connection before recycle. */ private readonly maxMessages; /** Factory that creates a socket adapter for each new connection. */ private readonly createAdapterFn; /** Optional token-bucket rate limiter, or null when disabled. */ private readonly rateLimiter; /** Active pooled SMTP connections. */ private readonly connections; /** Pending send operations waiting for a connection. */ private readonly queue; /** True while {@link close} is draining; rejects new sends. */ private draining; /** True after the pool has fully closed. */ private closed; /** Serializes queue processing to avoid concurrent drain races. */ private processChain; /** Creates an SMTP connection pool. */ constructor(config: SMTPConfig & PoolConfig, options?: SMTPPoolOptions); /** Sends a message through the pool. */ send(options: MailOptions): Promise; /** Schedules asynchronous processing of the send queue. */ private scheduleProcess; /** Verifies connectivity using a temporary connection. */ verify(): Promise; /** Drains the queue and closes all connections. */ close(): Promise; /** Current number of open pooled connections. */ get connectionCount(): number; /** Number of messages waiting in the send queue. */ get queueSize(): number; /** Dispatches queued messages to idle or newly spawned connections. */ private processQueue; /** Opens a new authenticated pooled SMTP connection. */ private spawnConnection; /** Removes a connection from the active pool list. */ private removeConnection; /** Waits until the send queue and in-flight work are fully drained. */ private drainQueue; } /** @internal Exposed for deterministic rate limiter tests. */ export { RateLimiter } from "../core/rate-limiter.js";