### Installation Source: https://context7.com/jasp402/easy-yopmail/llms.txt Install the Easy YOPmail library using npm or yarn. ```APIDOC ## Installation Install the Easy YOPmail library to start managing temporary emails in your Node.js project. ```bash # Using npm npm i easy-yopmail # Using yarn yarn add easy-yopmail ``` ``` -------------------------------- ### Install Easy YOPmail with npm or yarn Source: https://context7.com/jasp402/easy-yopmail/llms.txt Install the Easy YOPmail library to start managing temporary emails in your Node.js project. ```bash # Using npm npm i easy-yopmail ``` ```bash # Using yarn yarn add easy-yopmail ``` -------------------------------- ### Example Usage: Register with Temporary Email Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getMail.md Demonstrates how to generate a temporary email address using getMail() within an async function and handle potential errors. ```javascript const easyYopmail = require('easy-yopmail'); async function registerWithTemporaryEmail() { try { const temporaryEmail = await easyYopmail.getMail(); console.log("Temporary Email:", temporaryEmail); // Use the temporaryEmail for registration or testing purposes // ... } catch (error) { console.error("Error:", error); } } registerWithTemporaryEmail(); ``` -------------------------------- ### Install Easy-YOPmail Source: https://github.com/jasp402/easy-yopmail/blob/main/README.md Install the Easy-YOPmail library using npm. This is the first step to integrate the library into your Node.js project. ```bash npm i easy-yopmail ``` -------------------------------- ### Install Easy-Yopmail with Yarn Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/starter-topic.md Install the Easy-Yopmail library into your Node.js project using Yarn. ```xml yarn add easy-yopmail ``` -------------------------------- ### JavaScript Implementation Example Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/deleteMessage.md Example demonstrating how to use the `deleteMessage()` function in a JavaScript project. ```javascript const easyYopmail = require('easy-yopmail'); async function removeSpecificEmail() { try { const emailAddress = 'your-yopmail-address'; // Replace with the actual YOPmail address const messageId = 'your-email-id'; // Replace with the actual email ID obtained from getInbox() const result = await easyYopmail.deleteMessage(emailAddress, messageId); console.log(result); // Expected output examples: // Success // Email not found // Error: Unable to delete message } catch (error) { console.error("Error deleting message:", error); } } removeSpecificEmail(); ``` -------------------------------- ### Get Inbox and Read HTML Email Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/readMessage.md Demonstrates fetching the inbox for a YOPmail address and then reading the content of the first email in HTML format. Requires the 'easy-yopmail' package to be installed. ```javascript const easyYopmail = require('easy-yopmail'); easyYopmail.getInbox('test@yopmail.com') .then(inbox => { const emailId = inbox.inbox[0].id; easyYopmail.readMessage('test@yopmail.com', emailId, { format: 'HTML' }) .then(message => { console.log(message.content); // HTML content of the email }); }); ``` -------------------------------- ### Send Email using Easy-YOPMail writeMessage() Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/writeMessage.md Demonstrates how to send an email using the writeMessage function. Ensure you have the 'easy-yopmail' package installed and replace placeholder values with your actual YOPmail address and recipient details. Error handling is included for robustness. ```javascript const easyYopmail = require('easy-yopmail'); async function sendYopmail() { try { const mail = 'your-yopmail-address'; const to = 'recipient@example.com'; const subject = 'Test Email from YOPmail'; const body = 'This is a test email sent using Easy-YOPMail.'; const result = await easyYopmail.writeMessage(mail, to, subject, body); console.log(result); // Output: Success or error message } catch (error) { console.error("Error:", error); } } sendYopmail(); ``` -------------------------------- ### Get YOPmail Inbox Contents Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md Basic usage of getInbox() to retrieve all emails from a specified YOPmail address. Ensure the 'easy-yopmail' library is installed and imported. ```javascript const easyYopmail = require('easy-yopmail'); async function checkInbox() { try { const inbox = await easyYopmail.getInbox('your-yopmail-address'); console.log(inbox); // Output: A detailed inbox object containing email information } catch (error) { console.error("Error:", error); } } checkInbox(); ``` -------------------------------- ### Generate a temporary email address Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/starter-topic.md Use the `getMail()` function to dynamically generate a random and temporary email address. This is useful for scenarios requiring a unique email without manual setup. ```javascript const { getMail } = require('easy-yopmail'); async function generateEmail() { const email = await getMail(); console.log(email); } ``` -------------------------------- ### Retrieve Inbox Contents with Basic Retrieval Source: https://context7.com/jasp402/easy-yopmail/llms.txt Use the `getInbox()` function to retrieve the contents of a YOPmail inbox. This basic example shows how to fetch emails for a given inbox name. ```javascript const easyYopmail = require('easy-yopmail'); // Basic inbox retrieval async function checkInbox() { try { const inbox = await easyYopmail.getInbox('testing_01'); console.log(inbox); // Output: // { // settings: {}, // search: {}, // totalInbox: 271, // totalPages: 19, // mailFromPage: { page_1: 15 }, // totalGetMails: 15, // inbox: [ // { // id: 'e_ZwZjAGVlZGHlZQR1ZQNjAwZ5AQp4ZD==', // from: 'Ola no-reply', // subject: 'this is example message...', // timestamp: '10:20', // page: 1 // } // ] // } } catch (error) { console.error("Error:", error); } } ``` -------------------------------- ### Filter Emails by Sender with Wildcard Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md Use the 'from' parameter with a wildcard (%) to filter emails from senders whose addresses start with a specific string. This is useful for targeting emails from a particular domain or sender prefix. ```javascript const searchCriteria = { from: 'noreply%', // Emails from senders starting with 'noreply' }; const inbox = await easyYopmail.getInbox('your-yopmail-address', searchCriteria); ``` -------------------------------- ### Complete Workflow: Temporary Email Generation, Usage, and Cleanup Source: https://context7.com/jasp402/easy-yopmail/llms.txt Demonstrates a full workflow: generating a temporary email, simulating its use (e.g., for registration), waiting for and reading a verification email using a CSS selector, and finally cleaning up the inbox. ```javascript async function temporaryEmailWorkflow() { // 1. Generate temporary email const tempEmail = await easyYopmail.getMail(); const emailName = tempEmail.replace('@yopmail.com', ''); console.log(`Using temporary email: ${tempEmail}`); // 2. Use the email for registration/testing // await registerOnWebsite(tempEmail); // 3. Wait for and read verification email await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5 seconds const inbox = await easyYopmail.getInbox(emailName, { subject: '%verification%' }); if (inbox.inbox.length > 0) { const verificationEmail = await easyYopmail.readMessage( emailName, inbox.inbox[0].id, { format: 'HTML', selector: 'a.verify-link', attribute: 'href' } ); console.log("Verification link:", verificationEmail.content); } // 4. Cleanup - delete all emails const cleanup = await easyYopmail.deleteInbox(emailName); console.log("Cleanup:", cleanup); } temporaryEmailWorkflow(); ``` -------------------------------- ### getInbox() - Customizing Retrieval Settings Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md This snippet illustrates how to customize email retrieval using the `settings` parameter, including limiting the number of emails or pages, and setting the order. ```APIDOC ## GET /api/inbox (with settings) ### Description Retrieves inbox contents with customized settings for pagination, email limits, and sorting order. ### Method GET ### Endpoint /api/inbox ### Parameters #### Query Parameters - **mail** (String) - Required - The YOPmail email address (without the @yopmail.com domain). - **search** (Object) - Optional - An object containing search criteria to filter emails. - **settings** (Object) - Optional - An object containing settings for inbox retrieval. - **LIMIT_PAGE** (Number) - Optional - Maximum number of pages to explore (default: 10). Takes precedence over `LIMIT_MAIL`. - **LIMIT_MAIL** (Number) - Optional - Maximum number of emails to fetch (default: 0, no limit). - **ORDER** (String) - Optional - Order of returned emails (`'desc'` for newest first, `'asc'` for oldest first, default: `'desc'`). ### Request Example (Limit Pages and Order Ascending) ```javascript const easyYopmail = require('easy-yopmail'); async function customSettings() { const settings = { LIMIT_PAGE: 2, // Fetch emails from the latest 2 pages ORDER: 'asc', // Oldest emails first }; try { const inbox = await easyYopmail.getInbox('your-yopmail-address', null, settings); console.log(inbox); } catch (error) { console.error("Error:", error); } } customSettings(); ``` ### Request Example (Limit Emails) ```javascript const easyYopmail = require('easy-yopmail'); async function limitEmails() { const settings = { LIMIT_MAIL: 5, // Fetch a maximum of 5 emails }; try { const inbox = await easyYopmail.getInbox('your-yopmail-address', null, settings); console.log(inbox); } catch (error) { console.error("Error:", error); } } limitEmails(); ``` ### Response #### Success Response (200) - **inbox** (Object) - An object containing the inbox details with applied settings. - **count** (Number) - Total number of emails fetched based on settings. - **page** (Number) - Current page number. - **total_page** (Number) - Total number of pages available. - **emails** (Array) - An array of email objects, ordered and limited according to settings. - **id** (String) - Unique identifier for the email. - **from** (String) - Sender of the email. - **subject** (String) - Subject of the email. - **date** (String) - Date and time the email was received. - **short_date** (String) - Shortened date representation. - **is_yopmail** (Boolean) - Indicates if the email is from YOPmail. - **preview** (String) - A preview of the email content. - **link** (String) - A link to view the email. #### Response Example ```json { "count": 5, "page": 1, "total_page": 2, "emails": [ { "id": "1122334455", "from": "another@example.com", "subject": "Important Update", "date": "2023-10-26 15:00:00", "short_date": "Oct 26", "is_yopmail": false, "preview": "This is an important update.", "link": "/inbox/your-yopmail-address/1122334455" } ] } ``` ``` -------------------------------- ### Import Easy-YOPMail Library Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getMail.md Import the Easy-YOPMail library into your Node.js project before using its functions. ```javascript const easyYopmail = require('easy-yopmail'); ``` -------------------------------- ### Combine search criteria with all settings Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md Performs a search for emails from 'support%' with 'important' in the subject, exploring a maximum of 2 pages, stopping after 10 emails, and returning them sorted from oldest to newest. ```javascript const searchCriteria = { from: 'support%', subject: '%important%', }; const settings = { LIMIT_PAGE: 2, LIMIT_MAIL: 10, ORDER: 'asc', }; const inbox = await easyYopmail.getInbox('your-yopmail-address', searchCriteria, settings); // This will: // 1. Search for emails from 'support%' with 'important' in the subject. // 2. Explore a maximum of 2 pages. // 3. Stop after finding 10 matching emails. // 4. Return those 10 emails sorted from oldest to newest. console.log(inbox.inbox); ``` -------------------------------- ### getInbox() - Advanced Search with Wildcards Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md This snippet shows how to use the `search` parameter with wildcards for more flexible email filtering. ```APIDOC ## GET /api/inbox (with search parameters) ### Description Retrieves filtered inbox contents using wildcard searches for sender and subject. ### Method GET ### Endpoint /api/inbox ### Parameters #### Query Parameters - **mail** (String) - Required - The YOPmail email address (without the @yopmail.com domain). - **search** (Object) - Optional - An object containing search criteria. Supports partial matching for `from` and `subject` using the `%` wildcard. - **from** (String) - Optional - Filters emails by sender. Supports partial matching (e.g., `noreply%`). - **subject** (String) - Optional - Filters emails by subject. Supports partial matching (e.g., `%verification code%`). - **day** (String) - Optional - Filters emails by day (e.g., `Today`, `Yesterday`). - **settings** (Object) - Optional - An object containing settings for inbox retrieval. ### Request Example (Filtering by Sender) ```javascript const easyYopmail = require('easy-yopmail'); async function searchBySender() { const searchCriteria = { from: 'noreply%', // Emails from senders starting with 'noreply' }; try { const inbox = await easyYopmail.getInbox('your-yopmail-address', searchCriteria); console.log(inbox); } catch (error) { console.error("Error:", error); } } searchBySender(); ``` ### Request Example (Filtering by Subject) ```javascript const easyYopmail = require('easy-yopmail'); async function searchBySubject() { const searchCriteria = { subject: '%verification code%', // Emails with 'verification code' anywhere in the subject }; try { const inbox = await easyYopmail.getInbox('your-yopmail-address', searchCriteria); console.log(inbox); } catch (error) { console.error("Error:", error); } } searchBySubject(); ``` ### Request Example (Filtering by Day) ```javascript const easyYopmail = require('easy-yopmail'); async function searchByDay() { const searchCriteria = { day: 'Today', // Emails received today }; try { const inbox = await easyYopmail.getInbox('your-yopmail-address', searchCriteria); console.log(inbox); } catch (error) { console.error("Error:", error); } } searchByDay(); ``` ### Response #### Success Response (200) - **inbox** (Object) - An object containing the filtered inbox details and a list of emails matching the search criteria. - **count** (Number) - Total number of emails matching the criteria. - **page** (Number) - Current page number. - **total_page** (Number) - Total number of pages available. - **emails** (Array) - An array of email objects matching the search criteria. - **id** (String) - Unique identifier for the email. - **from** (String) - Sender of the email. - **subject** (String) - Subject of the email. - **date** (String) - Date and time the email was received. - **short_date** (String) - Shortened date representation. - **is_yopmail** (Boolean) - Indicates if the email is from YOPmail. - **preview** (String) - A preview of the email content. - **link** (String) - A link to view the email. #### Response Example ```json { "count": 5, "page": 1, "total_page": 1, "emails": [ { "id": "9876543210", "from": "noreply@example.com", "subject": "Your verification code is 12345", "date": "2023-10-27 09:30:00", "short_date": "Oct 27", "is_yopmail": false, "preview": "Your code is 12345.", "link": "/inbox/your-yopmail-address/9876543210" } ] } ``` ``` -------------------------------- ### Fetch up to 10 emails with default page limit Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md This scenario fetches up to 10 emails, allowing the function to explore as many pages as needed up to the default limit of 10 pages. ```javascript const settings_mail_limit = { LIMIT_MAIL: 10, }; const inbox_mail_limit = await easyYopmail.getInbox('your-yopmail-address', null, settings_mail_limit); // inbox_mail_limit.fetchedEmailCount will be 10 or less ``` -------------------------------- ### getInbox() - Basic Usage Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md This snippet demonstrates the basic usage of the getInbox() function to retrieve emails from a YOPmail inbox. ```APIDOC ## GET /api/inbox ### Description Retrieves the inbox contents of a specified YOPmail address. ### Method GET ### Endpoint /api/inbox ### Parameters #### Query Parameters - **mail** (String) - Required - The YOPmail email address (without the @yopmail.com domain). - **search** (Object) - Optional - An object containing search criteria to filter emails. Supports exact matching for `id`, `timestamp`, and `day`. For `from` and `subject`, it also supports partial matching using the `%` wildcard. - **settings** (Object) - Optional - An object containing settings for inbox retrieval. Supports `LIMIT_PAGE`, `LIMIT_MAIL`, and `ORDER`. ### Request Example ```javascript const easyYopmail = require('easy-yopmail'); async function checkInbox() { try { const inbox = await easyYopmail.getInbox('your-yopmail-address'); console.log(inbox); } catch (error) { console.error("Error:", error); } } checkInbox(); ``` ### Response #### Success Response (200) - **inbox** (Object) - An object containing the inbox details and a list of emails. - **count** (Number) - Total number of emails in the inbox. - **page** (Number) - Current page number. - **total_page** (Number) - Total number of pages available. - **emails** (Array) - An array of email objects. - **id** (String) - Unique identifier for the email. - **from** (String) - Sender of the email. - **subject** (String) - Subject of the email. - **date** (String) - Date and time the email was received. - **short_date** (String) - Shortened date representation. - **is_yopmail** (Boolean) - Indicates if the email is from YOPmail. - **preview** (String) - A preview of the email content. - **link** (String) - A link to view the email. #### Response Example ```json { "count": 15, "page": 1, "total_page": 1, "emails": [ { "id": "1234567890", "from": "sender@example.com", "subject": "Test Email", "date": "2023-10-27 10:00:00", "short_date": "Oct 27", "is_yopmail": false, "preview": "This is a test email content.", "link": "/inbox/your-yopmail-address/1234567890" } ] } ``` ``` -------------------------------- ### Explore up to 2 pages with default mail limit Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md This scenario explores up to 2 pages, fetching all emails found within those pages, with a potential maximum of 30 emails. ```javascript const settings_page_limit = { LIMIT_PAGE: 2, }; const inbox_page_limit = await easyYopmail.getInbox('your-yopmail-address', null, settings_page_limit); // inbox_page_limit.fetchedEmailCount will be 30 or less ``` -------------------------------- ### Save Full HTML Email Content to File Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/readMessage.md Save the complete HTML content of an email to a specified directory. Provide the 'HTML' format and the 'pathToSave' option. ```javascript easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', pathToSave: './emails' }) .then(message => { console.log('Email saved as HTML file'); }); ``` -------------------------------- ### Order results by ascending date Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md Fetches the 5 most recent emails and sorts them in ascending order, meaning the oldest of the 5 appears first. ```javascript const settings = { LIMIT_MAIL: 5, // Fetch the 5 most recent emails ORDER: 'asc', // Order them from oldest to newest }; const inbox = await easyYopmail.getInbox('your-yopmail-address', null, settings); // The inbox will contain the 5 most recent emails, // with the oldest of the 5 appearing first in the array. console.log(inbox.inbox); ``` -------------------------------- ### Combine LIMIT_PAGE and LIMIT_MAIL Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md This scenario requests 50 emails but is restricted by LIMIT_PAGE to a maximum of 30 emails (2 pages * 15 emails/page). ```javascript const settings_combined = { LIMIT_PAGE: 2, LIMIT_MAIL: 50, }; const inbox_combined = await easyYopmail.getInbox('your-yopmail-address', null, settings_combined); // inbox_combined.fetchedEmailCount will be 30 or less ``` -------------------------------- ### POST /api/send-email (writeMessage) Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/writeMessage.md The writeMessage() function sends an email from a specified YOPmail address to a recipient. It constructs the email content and sends an HTTP POST request to the YOPmail server. ```APIDOC ## POST /api/send-email (writeMessage) ### Description Sends an email from a YOPmail address to a specified recipient. ### Method POST ### Endpoint This function internally makes an HTTP POST request to the YOPmail server. The exact endpoint is managed by the library. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **mail** (String) - Required - The YOPmail email address (without the @yopmail.com domain) to send from. - **to** (String) - Required - The recipient's email address. - **subject** (String) - Required - The subject of the email. - **body** (String) - Required - The body of the email. ### Request Example ```javascript { "mail": "your-yopmail-address", "to": "recipient@example.com", "subject": "Test Email from YOPmail", "body": "This is a test email sent using Easy-YOPMail." } ``` ### Response #### Success Response (200) - **message** (String) - A confirmation message indicating the email was sent successfully. #### Response Example ```json { "message": "Email sent successfully" } ``` #### Error Response - **error** (String) - An error message describing the issue if the email sending fails. ``` -------------------------------- ### Filter Emails by Subject with Wildcard Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md Use the 'subject' parameter with a wildcard (%) to find emails containing a specific keyword anywhere within their subject line. This enables flexible searching for relevant messages. ```javascript const searchCriteria = { subject: '%verification code%', // Emails with 'verification code' anywhere in the subject }; const inbox = await easyYopmail.getInbox('your-yopmail-address', searchCriteria); ``` -------------------------------- ### Generate a Temporary Email Source: https://github.com/jasp402/easy-yopmail/blob/main/README.md Generate a random, disposable email address using the getMail function. The generated email is in the format [randomly generated name]@yopmail.com. ```javascript easyYopmail.getMail().then(email => { console.log(email); // Output: [randomly generated name]@yopmail.com }); ``` -------------------------------- ### getInbox() - Retrieve Inbox Contents Source: https://context7.com/jasp402/easy-yopmail/llms.txt The `getInbox()` function retrieves the contents of a YOPmail inbox with advanced search and filtering options. ```APIDOC ## GET /api/getInbox ### Description Retrieves the contents of a YOPmail inbox. Supports search filters for `id`, `timestamp`, `day`, `from`, and `subject` (with wildcard `%` support), and settings for pagination (`LIMIT_PAGE`), email limits (`LIMIT_MAIL`), and ordering (`ORDER`). ### Method GET ### Endpoint /api/getInbox ### Parameters #### Query Parameters - **emailAddress** (string) - Required - The YOPmail address to retrieve the inbox for. - **searchCriteria** (object) - Optional - Criteria to filter emails. Supports `id`, `timestamp`, `day`, `from`, `subject` with wildcard `%`. - **from** (string) - Optional - Sender's email address or pattern. - **subject** (string) - Optional - Email subject or pattern. - **day** (string) - Optional - Filter by day (e.g., 'Today', 'Yesterday'). - **settings** (object) - Optional - Settings for pagination and ordering. - **LIMIT_PAGE** (number) - Optional - Maximum number of pages to retrieve. - **LIMIT_MAIL** (number) - Optional - Maximum number of emails to retrieve. - **ORDER** (string) - Optional - Order of emails ('asc' or 'desc'). ### Request Example ```javascript const easyYopmail = require('easy-yopmail'); // Basic inbox retrieval async function checkInbox() { try { const inbox = await easyYopmail.getInbox('testing_01'); console.log(inbox); } catch (error) { console.error("Error:", error); } } // Advanced search with wildcards const searchCriteria = { from: 'noreply%', // Emails from senders starting with 'noreply' subject: '%verification%' // Emails with 'verification' in subject }; const settings = { LIMIT_PAGE: 2, // Explore max 2 pages (30 emails max) LIMIT_MAIL: 10, // Return max 10 emails ORDER: 'asc' // Oldest first }; easyYopmail.getInbox('my-email', searchCriteria, settings).then(inbox => { console.log(`Found ${inbox.totalGetMails} matching emails`); inbox.inbox.forEach(email => { console.log(`[${email.timestamp}] ${email.from}: ${email.subject}`); }); }); // Filter by day easyYopmail.getInbox('my-email', { day: 'Today' }).then(inbox => { console.log("Today's emails:", inbox.inbox); }); ``` ### Response #### Success Response (200) - **settings** (object) - The settings used for the query. - **search** (object) - The search criteria used for the query. - **totalInbox** (number) - The total number of emails in the inbox. - **totalPages** (number) - The total number of pages available. - **mailFromPage** (object) - An object detailing the number of emails per page. - **totalGetMails** (number) - The total number of emails retrieved matching the criteria. - **inbox** (array) - An array of email objects. - **id** (string) - Unique identifier for the email. - **from** (string) - Sender of the email. - **subject** (string) - Subject of the email. - **timestamp** (string) - Time the email was received. - **page** (number) - The page number the email belongs to. ``` -------------------------------- ### Generate Temporary Email Address Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getMail.md Invoke the getMail() function to obtain a random email address. This function returns a Promise that resolves with the generated email. ```javascript easyYopmail.getMail().then(email => { console.log(email); // Output: [randomly generated name]@yopmail.com }); ``` -------------------------------- ### getMail() - Generate Random Email Address Source: https://context7.com/jasp402/easy-yopmail/llms.txt The `getMail()` function dynamically generates a random temporary email address from YOPmail. ```APIDOC ## GET /api/getMail ### Description Dynamically generates a random temporary email address from YOPmail. Useful for automated testing, web scraping, and anonymous sign-ups. ### Method GET ### Endpoint /api/getMail ### Request Example ```javascript const easyYopmail = require('easy-yopmail'); // Basic usage - generate a random temporary email easyYopmail.getMail().then(email => { console.log(email); // Output: "randomname123@yopmail.com" }); // With async/await and error handling async function registerWithTemporaryEmail() { try { const temporaryEmail = await easyYopmail.getMail(); console.log("Temporary Email:", temporaryEmail); return temporaryEmail; } catch (error) { console.error("Error generating email:", error); throw error; } } registerWithTemporaryEmail(); ``` ### Response #### Success Response (200) - **email** (string) - The generated random email address (e.g., "randomname123@yopmail.com"). ``` -------------------------------- ### Read Email and Save Attachments Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/readMessage.md Read an email and save its attachments. Set 'saveAttachment' to true. Note that this can impact performance and requires the email to have attachments. ```javascript easyYopmail.readMessage('my-email', 'email-id', { saveAttachment: true }) .then(message => { if (message.saveAttachments) { console.log('Attachments saved to download folder'); } }); // Output: // Attachments saved to download folder attachments: [ { fullName: 'prueba1.rar', name: 'prueba1', extension: 'rar', file: 'https://yopmail.com//cid?b=jasp402&id=e_ZwDkZGN4ZGVmZQR5ZQNjAGD4AwL5BD==&cd=a&pj=f_m38pqbyv1' }, { fullName: 'prueba2.zip', name: 'prueba2', extension: 'zip', file: 'https://yopmail.com//cid?b=jasp402&id=e_ZwDkZGN4ZGVmZQR5ZQNjAGD4AwL5BD==&cd=a&pj=f_m38pqbyg0' } ] ``` -------------------------------- ### Advanced Inbox Search and Filtering Source: https://context7.com/jasp402/easy-yopmail/llms.txt Retrieve inbox contents with advanced search filters for `id`, `timestamp`, `day`, `from`, and `subject` (with wildcard `%` support). Settings for pagination, email limits, and ordering are also supported. ```javascript // Advanced search with wildcards const searchCriteria = { from: 'noreply%', // Emails from senders starting with 'noreply' subject: '%verification%' // Emails with 'verification' in subject }; const settings = { LIMIT_PAGE: 2, // Explore max 2 pages (30 emails max) LIMIT_MAIL: 10, // Return max 10 emails ORDER: 'asc' // Oldest first }; easyYopmail.getInbox('my-email', searchCriteria, settings).then(inbox => { console.log(`Found ${inbox.totalGetMails} matching emails`); inbox.inbox.forEach(email => { console.log(`[${email.timestamp}] ${email.from}: ${email.subject}`); }); }); ``` ```javascript // Filter by day easyYopmail.getInbox('my-email', { day: 'Today' }).then(inbox => { console.log("Today's emails:", inbox.inbox); }); ``` -------------------------------- ### Read Email Content - readMessage() Source: https://context7.com/jasp402/easy-yopmail/llms.txt Reads the content of a specific email by its unique ID. Supports various options for format, content extraction, and file handling. ```APIDOC ## readMessage() ### Description Reads the content of a specific email by its unique ID. It supports options for format (`TXT` or `HTML`), CSS selector targeting to extract specific elements, attribute extraction (e.g., `href` from links), saving HTML to file, and downloading attachments. ### Method `easyYopmail.readMessage(mailAddress, emailId, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Options Object - **format** (string) - Optional - The format of the email content. Accepts `TXT` (default) or `HTML`. - **selector** (string) - Optional - A CSS selector to target specific elements within the HTML content. - **attribute** (string) - Optional - The attribute to extract from the selected element (e.g., `href`). - **pathToSave** (string) - Optional - The path to save the email's HTML content to a file. - **saveAttachment** (boolean) - Optional - If `true`, attempts to download attachments associated with the email. ### Request Example ```javascript // Read email in plain text format (default) easyYopmail.readMessage('my-email', 'e_ZwZjAGVlZGHlZQR1ZQNjAwZ5AQp4ZD==') .then(message => { console.log(message); }); // Read email in HTML format easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML' }) .then(message => { console.log(message.content); // Full HTML content }); // Extract confirmation link using CSS selector easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', selector: 'a.confirmation-link', attribute: 'href' }).then(message => { console.log("Confirmation URL:", message.content); }); // Save email HTML to file easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', pathToSave: './emails' }).then(message => { console.log('Email saved to:', message.pathToSave); }); // Download attachments easyYopmail.readMessage('my-email', 'email-id', { saveAttachment: true }) .then(message => { if (message.attachments && message.attachments.length > 0) { console.log('Attachments:', message.attachments); } }); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the email. - **submit** (string) - The subject of the email. - **from** (string) - The sender's email address. - **date** (string) - The date and time the email was sent. - **deliverability** (string) - Information about email deliverability. - **format** (string) - The format of the returned content (`txt` or `html`). - **content** (string) - The main body content of the email. - **info** (array) - Additional information about the email. - **pathToSave** (string) - If `pathToSave` option was used, this field indicates the path where the email was saved. - **attachments** (array) - If `saveAttachment` option was used, this array contains details of the downloaded attachments. #### Response Example ```json { "id": "e_ZwZjAGVlZGHlZQR1ZQNjAwZ5AQp4ZD==", "submit": "ITechnoLabs Notification", "from": "notifications@example.com", "date": "Monday, May 22, 2023 10:23:26 PM", "deliverability": "...", "format": "txt", "content": "Email body text content...", "info": [] } ``` ``` -------------------------------- ### Send Email - writeMessage() Source: https://context7.com/jasp402/easy-yopmail/llms.txt Sends emails from a YOPmail address to a specified recipient. Useful for automated notifications and testing. ```APIDOC ## writeMessage() ### Description Sends emails from a YOPmail address. It accepts the sender's YOPmail address, recipient's email, subject, and body content. This is useful for automated notifications, testing email workflows, and sending messages from temporary addresses. ### Method `easyYopmail.writeMessage(senderMailAddress, recipientEmailAddress, subject, body)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Arguments - **senderMailAddress** (string) - Required - The YOPmail address of the sender (without `@yopmail.com`). - **recipientEmailAddress** (string) - Required - The recipient's email address (without `@yopmail.com`). - **subject** (string) - Required - The subject line of the email. - **body** (string) - Required - The content of the email message. ### Request Example ```javascript // Send a basic email async function sendYopmail() { try { const mail = 'my-temp-email'; // Sender (without @yopmail.com) const to = 'recipient'; // Recipient (without @yopmail.com) const subject = 'Test Email from YOPmail'; const body = 'This is a test email sent using Easy-YOPMail library.'; const result = await easyYopmail.writeMessage(mail, to, subject, body); console.log(result); } catch (error) { console.error("Error sending email:", error); } } sendYopmail(); // Complete notification workflow async function sendNotification(recipientEmail, notificationMessage) { const senderEmail = 'automated-notifications'; const subject = `Notification: ${new Date().toLocaleDateString()}`; try { await easyYopmail.writeMessage( senderEmail, recipientEmail, subject, notificationMessage ); console.log(`Notification sent to ${recipientEmail}`); return true; } catch (error) { console.error(`Failed to send notification: ${error.message}`); return false; } } sendNotification('test-recipient', 'Your task has been completed successfully.'); ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the email was sent successfully. #### Response Example ```json "Your message has been sent" ``` ``` -------------------------------- ### Filter Emails by Day Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/getInbox.md Filter emails received on a specific day by using the 'day' parameter. Supported values include 'Today', 'Yesterday', or a specific date string. ```javascript const searchCriteria = { day: 'Today', // Emails received today }; const inbox = await easyYopmail.getInbox('your-yopmail-address', searchCriteria); ``` -------------------------------- ### Read Email Inbox Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/starter-topic.md Fetches the inbox for a given temporary email address. The result contains an array of email objects, each with properties like id, from, subject, and timestamp. ```javascript const easyYopmail = require('easy-yopmail'); easyYopmail.getInbox('testEmail@yopmail.com').then(email=>{ console.log(email.inbox); //we obtain an object with the property "Inbox" which is an array of objects //that contain the emails found. { id: 'e_ZwDjZmZkZwV0ZGN1ZQNjAGN1ZGLlBN==', from: 'Disqus', subject: 'Re: Comment on Rehab Afterlife', timestamp: '17:41', page: 5 } }); ``` -------------------------------- ### Send Email with Easy-YOPmail Source: https://context7.com/jasp402/easy-yopmail/llms.txt Sends emails from a YOPmail address. Accepts sender's YOPmail address, recipient's email, subject, and body content. Useful for automated notifications and testing email workflows. ```javascript const easyYopmail = require('easy-yopmail'); // Send a basic email async function sendYopmail() { try { const mail = 'my-temp-email'; // Sender (without @yopmail.com) const to = 'recipient'; // Recipient (without @yopmail.com) const subject = 'Test Email from YOPmail'; const body = 'This is a test email sent using Easy-YOPMail library.'; const result = await easyYopmail.writeMessage(mail, to, subject, body); console.log(result); // Output: "Your message has been sent" } catch (error) { console.error("Error sending email:", error); } } sendYopmail(); ``` ```javascript // Complete notification workflow async function sendNotification(recipientEmail, notificationMessage) { const senderEmail = 'automated-notifications'; const subject = `Notification: ${new Date().toLocaleDateString()}`; try { await easyYopmail.writeMessage( senderEmail, recipientEmail, subject, notificationMessage ); console.log(`Notification sent to ${recipientEmail}`); return true; } catch (error) { console.error(`Failed to send notification: ${error.message}`); return false; } } sendNotification('test-recipient', 'Your task has been completed successfully.'); ``` -------------------------------- ### Delete Entire Inbox - JavaScript Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/starter-topic.md Call the deleteInbox() function with the email address to empty the inbox. The response indicates success and the number of emails deleted. ```javascript const easyYopmail = require('easy-yopmail'); easyYopmail.deleteInbox('example@yopmail.com') .then(response => { console.log(response); // Output: "The inbox of the email [example@yopmail.com] has been deleted. X emails have been deleted." }); ``` -------------------------------- ### Read Email Content with Easy-YOPmail Source: https://context7.com/jasp402/easy-yopmail/llms.txt Reads the content of a specific email by its unique ID. Supports options for format, CSS selector targeting, attribute extraction, saving HTML to file, and downloading attachments. ```javascript const easyYopmail = require('easy-yopmail'); // Read email in plain text format (default) easyYopmail.readMessage('my-email', 'e_ZwZjAGVlZGHlZQR1ZQNjAwZ5AQp4ZD==') .then(message => { console.log(message); // Output: // { // id: 'e_ZwZjAGVlZGHlZQR1ZQNjAwZ5AQp4ZD==', // submit: 'ITechnoLabs Notification', // from: 'notifications@example.com', // date: 'Monday, May 22, 2023 10:23:26 PM', // deliverability: '...', // format: 'txt', // content: 'Email body text content...', // info: [] // } }); ``` ```javascript // Read email in HTML format easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML' }) .then(message => { console.log(message.content); // Full HTML content }); ``` ```javascript // Extract confirmation link using CSS selector easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', selector: 'a.confirmation-link', attribute: 'href' }).then(message => { console.log("Confirmation URL:", message.content); // Output: "https://example.com/confirm?token=abc123" }); ``` ```javascript // Save email HTML to file easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', pathToSave: './emails' }).then(message => { console.log('Email saved to:', message.pathToSave); }); ``` ```javascript // Download attachments easyYopmail.readMessage('my-email', 'email-id', { saveAttachment: true }) .then(message => { if (message.attachments && message.attachments.length > 0) { console.log('Attachments:', message.attachments); // Output: // [ // { fullName: 'document.pdf', name: 'document', extension: 'pdf', file: 'https://...' }, // { fullName: 'image.png', name: 'image', extension: 'png', file: 'https://...' } // ] } }); ``` ```javascript // Complete workflow: get inbox then read latest email async function readLatestEmail(mailAddress) { const inbox = await easyYopmail.getInbox(mailAddress); if (inbox.inbox.length === 0) { console.log("No emails found"); return null; } const latestEmailId = inbox.inbox[0].id; const message = await easyYopmail.readMessage(mailAddress, latestEmailId, { format: 'HTML' }); console.log(`Subject: ${message.submit}`); console.log(`From: ${message.from}`); console.log(`Date: ${message.date}`); return message; } readLatestEmail('testing_account'); ``` -------------------------------- ### Read Plain Text Email Content Source: https://github.com/jasp402/easy-yopmail/blob/main/Writerside/topics/readMessage.md Use this snippet to retrieve the plain text content of an email. Ensure you have the correct email address and ID. ```javascript easyYopmail.readMessage('my-email', 'email-id') .then(message => { console.log(message.content); // Plain text content of the email }); ```