UNPKG

temp-disposable-email

Version:

Generating Temporary email address for testing, retrieving email from the temporary email address

80 lines 3.17 kB
export interface GeneratedEmail { emailAddress: string; accountId: string; } export interface MessageContent { from: { address: string; }; to: { address: string; }[]; subject: string; intro: string; text: string; html: string[]; createdAt: string; updatedAt: string; attachments: Attachment[]; } interface Attachment { title: string; data: Buffer; } export interface GetEmailOptions { maxWaitTime?: number; waitInterval?: number; logPolling?: boolean; deleteAfterRead?: boolean; } export declare const delay: (ms: number) => Promise<void>; /** * Creates a new email inbox with a unique address. * * This function generates an temp inbox & email address * * @param {string} [emailPrefix] - Optional emailPrefix; a random one is generated if not provided. * @returns {Promise<GeneratedEmail>} The generated email address & account ID. * * @throws {Error} If no domains are available or account creation fails. * * @example * const email = await generateEmail("customUser"); * console.log(email); // Outputs: {"emailAddress": "customUser@mail.tm" , "accountId": "1234"} */ export declare const generateEmail: (emailPrefix?: string) => Promise<GeneratedEmail>; /** * Retrieves the latest message from the inbox. * * @param {GetEmailOptions} [options] - Optional settings for polling and deletion. * @param {number} [options.maxWaitTime=30000] - Maximum time to wait for messages (in milliseconds). Default is 30 seconds. * @param {number} [options.waitInterval=2000] - Time interval between polling attempts (in milliseconds). Default is 2 seconds. * @param {boolean} [options.logPolling=false] - Whether to log polling attempts. Default is `false`. * @param {boolean} [options.deleteAfterRead=false] - Whether to delete the message after reading. Default is `false`. * @returns {Promise<MessageContent | null>} The email content (sender, recipient, subject, text, HTML), or `null` if no messages are found. * * @throws {Error} If no messages are available within the polling timeout or authentication fails. * * @example * const message = await getRecentEmail({ maxWaitTime: 5000, waitInterval: 1000, logPolling: true }); * console.log(message.subject); // Outputs: "Hello!" */ export declare const getRecentEmail: (options?: GetEmailOptions) => Promise<MessageContent | null>; /** * Extracts a verification code from the provided email content. * * This function scans the given text for a sequence of 5 or more * consecutive digits and returns the first valid verification code. * If no valid sequence is found, the function returns `null`. * * @param {string} text - The content of the email, typically the body. * @returns {Promise<string | null>} The first verification code found, or `null` if no valid code exists. * * @example * const emailContent = "Your code is 123456."; * const verificationCode = await getVerificationCode(emailContent); * console.log(verificationCode); // Output: "123456" */ export declare const getVerificationCode: (text: string | undefined) => Promise<string>; export {}; //# sourceMappingURL=index.d.ts.map