UNPKG

@timshel_npm/maildev

Version:

SMTP Server with async API and Web Interface for viewing and testing emails during development

116 lines (115 loc) 3.38 kB
/** * MailDev - mailserver */ import type { Attachment, Envelope, Mail } from "./type"; import type { OutgoingOptions } from "./outgoing"; import type { ReadStream } from "fs"; import { MailBuffer } from "./mailbuffer"; import { Outgoing } from "./outgoing"; import { SMTPServer } from "smtp-server"; export interface MailServerOptions { port?: number; host?: string; mailDir?: string; hideExtensions?: string[]; isSecure?: boolean; auth?: { user: string; pass: string; }; ssl?: { certPath: string; keyPath: string; }; hide8BITMIME?: boolean; hidePIPELINING?: boolean; hideSMTPUTF8?: boolean; outgoing?: OutgoingOptions; } export declare class MailServer { port: number; host: string; mailDir: string; store: Envelope[]; eventEmitter: any; mailEventSubjectMapper: (Mail: any) => string | undefined; smtp: typeof SMTPServer; outgoing: Outgoing | undefined; /** * Extend Event Emitter methods * events: * 'new' - emitted when new email has arrived */ emit: any; on: any; off: any; once: any; prependListener: any; prependOnceListener: any; removeListener: any; removeAllListeners: any; next(subject: string): Promise<Mail>; /** * Use an internal array to store received email even if not consummed * Use `.return()` to close it **/ iterator(subject: string): AsyncIterator<Mail>; /** * Return a struct which store received emails. * Then allow to obtain a `Promise<Mail>` dependant on a predicate `(Mail) => boolean`. * Allow to wait for `Mail` independant of their order of arrival. */ buffer(subject: string, defaultTimeout?: number): MailBuffer; constructor(options?: MailServerOptions, mailEventSubjectMapper?: (Mail: any) => string | undefined); /** * Start the mailServer */ listen(): Promise<void>; /** * Stop the mailserver */ close(): Promise<void>; isOutgoingEnabled(): boolean; getOutgoingHost(): string | undefined; /** * Set Auto Relay Mode, automatic send email to recipient */ setAutoRelayMode(enabled: boolean, emailAddress: string | undefined, rules: { allow?: string; deny?: string; }[] | string | undefined): void; relayMail(mail: Mail, isAutoRelay?: boolean): Promise<void>; /** * Get an email by id */ getEmail(id: string): Promise<Mail>; /** * Returns a readable stream of the raw email */ getRawEmail(id: string): Promise<ReadStream>; /** * Returns the html of a given email */ getEmailHTML(id: string, baseUrl?: string): Promise<string>; /** * Set all emails to read */ readAllEmail(): number; getAllEnvelope(): Envelope[]; getAllEmail(): Promise<Mail[]>; deleteEmail(id: string): Promise<boolean>; deleteAllEmail(): Promise<boolean>; /** * Delete everything in the mail directory */ clearMailDir(): Promise<void[]>; /** * Returns the content type and a readable stream of the file */ getEmailAttachment(id: string, filename: string): Promise<Attachment>; /** * Download a given email */ getEmailEml(id: any): Promise<[string, string, ReadStream]>; loadMailsFromDirectory(): Promise<void[]>; }