/** * Email Testing Handler * * P1 - Email testing for applications that send emails * * Supports: * - Mailhog integration * - Mailtrap integration * - Mailgun API * - SendGrid API * - Generic IMAP/POP3 access * - Email parsing and validation * - Link extraction from emails * - Attachment handling * * @see https://github.com/mailhog/MailHog */ export interface EmailConfig { /** Mailhog API base URL (e.g., http://localhost:8025) */ mailhogUrl?: string; /** Mailtrap API token */ mailtrapToken?: string; /** Mailgun API key */ mailgunApiKey?: string; /** SendGrid API key */ sendgridApiKey?: string; /** Default timeout for email operations (ms) */ timeout?: number; } export interface EmailMessage { /** Message ID */ id: string; /** From address */ from: string; /** To addresses */ to: string[]; /** CC addresses */ cc?: string[]; /** Subject */ subject: string; /** Plain text body */ text?: string; /** HTML body */ html?: string; /** Received timestamp */ received: Date; /** Attachments */ attachments?: EmailAttachment[]; /** Custom headers */ headers?: Record; } export interface EmailAttachment { /** Filename */ filename: string; /** Content type */ contentType: string; /** Size in bytes */ size: number; /** Download URL (if available) */ downloadUrl?: string; } export interface EmailSearchOptions { /** Filter by recipient */ to?: string; /** Filter by sender */ from?: string; /** Filter by subject (partial match) */ subject?: string; /** Filter by content (partial match) */ contains?: string; /** Minimum received date */ after?: Date; /** Maximum received date */ before?: Date; } /** * Email Testing Handler class */ export declare class EmailTestingHandler { private mailhogUrl; private timeout; private mailtrapToken?; private mailgunApiKey?; private sendgridApiKey?; constructor(config?: EmailConfig); /** * Fetch all messages from Mailhog */ fetchMessages(): Promise; /** * Delete all messages from Mailhog */ deleteAllMessages(): Promise; /** * Get a specific message by ID */ getMessage(id: string): Promise; /** * Wait for a new email matching criteria */ waitForEmail(options?: EmailSearchOptions, timeout?: number): Promise; /** * Search for messages matching criteria */ searchMessages(options: EmailSearchOptions): Promise; /** * Get the most recent email matching criteria */ getLatestEmail(options?: EmailSearchOptions): Promise; /** * Extract all links from an email */ extractLinks(message: EmailMessage): { textLinks: string[]; htmlLinks: string[]; allLinks: string[]; }; /** * Extract verification links (common patterns) */ extractVerificationLinks(message: EmailMessage): { verifyEmail: string[]; resetPassword: string[]; unsubscribe: string[]; other: string[]; }; /** * Extract OTP/code from email */ extractCode(message: EmailMessage): { code?: string; type?: 'numeric' | 'alphanumeric'; confidence: number; }; /** * Parse a Mailhog message */ private parseMailhogMessage; /** * Parse email address from string */ private parseEmailAddress; /** * Parse attachments from Mailhog format */ private parseAttachments; /** * Check if message matches search criteria */ private matchesCriteria; /** * Assert email was received */ assertEmailReceived(options: EmailSearchOptions, timeout?: number): Promise<{ received: boolean; email?: EmailMessage; error?: string; }>; /** * Assert email contains link */ assertEmailContainsLink(message: EmailMessage, linkPattern: string | RegExp): { contains: boolean; foundLinks: string[]; }; /** * Get Mailhog status */ getMailhogStatus(): Promise<{ available: boolean; error?: string; }>; private sleep; /** * Fetch messages from Mailtrap (alternative to Mailhog) */ fetchMailtrapMessages(inboxId?: string): Promise; /** * Parse Mailtrap message */ private parseMailtrapMessage; /** * Create email testing utilities for test helpers */ createTestHelpers(): { waitForEmail: (options?: EmailSearchOptions, timeout?: number) => Promise; getLatestEmail: (options?: EmailSearchOptions) => Promise; extractLinks: (message: EmailMessage) => { textLinks: string[]; htmlLinks: string[]; allLinks: string[]; }; extractCode: (message: EmailMessage) => { code?: string; type?: "numeric" | "alphanumeric"; confidence: number; }; deleteAll: () => Promise; assertEmailReceived: (options: EmailSearchOptions, timeout?: number) => Promise<{ received: boolean; email?: EmailMessage; error?: string; }>; }; } /** * Factory function to create Email Testing Handler */ export declare function createEmailTestingHandler(config?: EmailConfig): EmailTestingHandler; /** * Quick function to wait for email */ export declare function waitForEmail(config: EmailConfig, options: EmailSearchOptions, timeout?: number): Promise; export default EmailTestingHandler;