/** * @module * Inbucket development transport — SMTP to a local Inbucket catcher with * REST helpers for inspecting, reading, and purging mailbox messages. * * Defaults match a stock Inbucket install: SMTP `localhost:2500`, * UI/API `http://localhost:9000`. * * @example * ```ts * import { createMailer } from "sently/mailer"; * import { InbucketTransport } from "sently/transports/inbucket"; * * const inbucket = new InbucketTransport(); * const mailer = await createMailer({ transport: inbucket }); * * await mailer.send({ * from: "dev@example.com", * to: "you@example.com", * subject: "Hello", * text: "Captured by Inbucket", * }); * * const mailbox = inbucket.mailboxForAddress("you@example.com"); * const inbox = await inbucket.listMailbox(mailbox); * console.log(inbox[0]?.subject); * ``` */ import { SentlyError } from "../core/errors.js"; import type { MailOptions, SendResult, SMTPAuth, SocketAdapter, TLSOptions, Transport, VerifyResult } from "../core/types.js"; /** Default SMTP host for a local Inbucket instance. */ export declare const INBUCKET_DEFAULT_HOST = "localhost"; /** Default SMTP port for a local Inbucket instance. */ export declare const INBUCKET_DEFAULT_PORT = 2500; /** Default web UI / REST API base URL for a local Inbucket instance. */ export declare const INBUCKET_DEFAULT_API_URL = "http://localhost:9000"; /** * How Inbucket maps an email address to a mailbox name. * Matches `INBUCKET_MAILBOXNAMING` on the catcher (`local` by default). */ export type InbucketMailboxNaming = "local" | "full" | "domain"; /** Inbucket development transport configuration. */ export interface InbucketConfig { /** SMTP hostname. Default: `"localhost"`. */ host?: string; /** SMTP port. Default: `2500`. */ port?: number; /** Use implicit TLS on connect. Default: `false` (Inbucket is plain SMTP). */ secure?: boolean; /** * Refuse AUTH over a non-TLS connection. * Default: `false` so optional local SMTP auth works without TLS. */ requireTLS?: boolean; /** Optional SMTP authentication. */ auth?: SMTPAuth; /** TLS options when STARTTLS or implicit TLS is enabled. */ tls?: TLSOptions; /** Socket connect timeout in milliseconds. */ connectionTimeout?: number; /** Runtime socket adapter. Auto-detected on first send when omitted. */ adapter?: SocketAdapter; /** * Inbucket web UI / REST API base URL (no trailing slash). * Default: `"http://localhost:9000"`. */ apiUrl?: string; /** * Mailbox naming strategy for {@link InbucketTransport.mailboxForAddress}. * Default: `"local"` (local-part only), matching stock Inbucket. */ mailboxNaming?: InbucketMailboxNaming; } /** Summary row from `GET /api/v1/mailbox/{name}`. */ export interface InbucketMessageHeader { /** Mailbox name. */ mailbox: string; /** Inbucket message id. */ id: string; /** Sender address string. */ from: string; /** Recipient address strings. */ to: string[]; /** Subject line. */ subject: string; /** ISO created timestamp. */ date: string; /** Unix epoch milliseconds. */ "posix-millis": number; /** Message size in bytes. */ size: number; /** Whether the message has been seen in the UI/API. */ seen: boolean; } /** Attachment metadata from a full Inbucket message. */ export interface InbucketAttachment { /** Attachment filename. */ filename: string; /** MIME content type. */ "content-type": string; /** Absolute download URL served by Inbucket. */ "download-link": string; /** Absolute view URL served by Inbucket. */ "view-link": string; /** MD5 checksum of the attachment bytes. */ md5: string; } /** Body parts from a full Inbucket message. */ export interface InbucketMessageBody { /** Plain-text body. */ text: string; /** HTML body. */ html: string; } /** Full message from `GET /api/v1/mailbox/{name}/{id}`. */ export interface InbucketMessage extends InbucketMessageHeader { /** Text and HTML bodies. */ body: InbucketMessageBody; /** Parsed header map. */ header: Record; /** Attachments (may be empty). */ attachments: InbucketAttachment[]; } /** Error thrown when the Inbucket REST API returns a non-success response. */ export declare class InbucketError extends SentlyError { readonly statusCode: number; readonly apiError: unknown; /** Creates an Inbucket API error with status code (`0` = network/connect failure). */ constructor(message: string, statusCode: number, apiError: unknown); } /** * Development transport for [Inbucket](https://inbucket.org/). * * Sends via SMTP (defaults: `localhost:2500`) and exposes REST helpers for * listing, reading, marking seen, deleting, and purging mailbox messages. */ export declare class InbucketTransport implements Transport { readonly provider = "inbucket"; private readonly host; private readonly port; private readonly secure; private readonly requireTLS; private readonly auth?; private readonly tls?; private readonly connectionTimeout?; private readonly adapter?; private readonly apiUrl; private readonly mailboxNaming; private smtp; /** Creates an Inbucket transport with local-dev defaults. */ constructor(config?: InbucketConfig); /** Web UI base URL (same origin as the REST API). */ get webUrl(): string; /** Sends an email to Inbucket over SMTP. */ send(options: MailOptions): Promise; /** Verifies SMTP connectivity to Inbucket. */ verify(): Promise; /** Closes the underlying SMTP adapter if connected. */ close(): Promise; /** * Maps an email address to an Inbucket mailbox name using {@link mailboxNaming}. * Stock Inbucket uses `"local"` (the part before `@`). */ mailboxForAddress(address: string): string; /** * Lists messages in a mailbox via `GET /api/v1/mailbox/{name}`. * Newest messages appear last in a stock Inbucket response. */ listMailbox(mailbox: string): Promise; /** * Fetches a full message via `GET /api/v1/mailbox/{name}/{id}`. */ getMessage(mailbox: string, id: string): Promise; /** * Fetches the raw message source via `GET /api/v1/mailbox/{name}/{id}/source`. */ getSource(mailbox: string, id: string): Promise; /** * Marks a message as seen via `PATCH /api/v1/mailbox/{name}/{id}`. */ markSeen(mailbox: string, id: string): Promise; /** * Deletes one message via `DELETE /api/v1/mailbox/{name}/{id}`. */ deleteMessage(mailbox: string, id: string): Promise; /** * Deletes every message in a mailbox via `DELETE /api/v1/mailbox/{name}`. */ purgeMailbox(mailbox: string): Promise; private encodeSegment; private getSmtp; private apiHeaders; private apiFetch; private apiJson; private apiOk; }