UNPKG

test-smtp-server

Version:

The test-smtp-server package allows internal testing of projects needing an SMTP server.

69 lines (68 loc) 2.07 kB
import { SMTPServerEnvelope } from "smtp-server"; import { ParsedMail } from "mailparser"; /** * Class to describe an email. The `envelope` contains the SMTP routing * information. This may not match the `to/cc/bcc` information in the * email contaents. The buffer contains the raw email content. To easily * access parts of the email, `getParsed` should be used. */ export declare class eMail { envelope: SMTPServerEnvelope; buffer: Buffer | null; length: number; constructor(envelope: SMTPServerEnvelope, buffer: Buffer); /** * Return a parsed email as formatted by `simpleParser`. * * @returns Promise<ParsedMail> See * https://nodemailer.com/extras/mailparser/ for the structure. */ getParsed(): Promise<ParsedMail>; } /** * testSmtpServer optional parameters */ export type testSmtpServerOptions = { /** the port number to use (default: 1025) */ smtpPort?: number; /** restrict ip addresses to localhost */ localhostOnly?: boolean; /** logging function like console.log() */ debug?: (message?: unknown, ...optionalParams: any[]) => void; }; /** * Create a testSmtpServer. This provides a wrapper to SMTPServer that * can be used for testing. The emails are stored in an array that * can be examined to validate the content. */ export declare class testSmtpServer { private debug; private emails; private isDebugging; private localhostOnly; private port; private server; constructor(options?: testSmtpServerOptions); /** * Clear the set of emails. * * @returns number of emails deleted */ clearEmails(): number; /** * Retrieve the set of emails in order from oldest to most recent. * * @returns array of eMail objects */ getEmails(): eMail[]; /** * Query for the port number used by the server. * * @returns the port number being used */ getPort(): number; /** Start the server */ startServer(): void; /** Stop the server */ stopServer(): void; }