📬 getInbox()
The getInbox() function in the Easy-YOPMail library provides a streamlined way to access and retrieve the contents of a YOPmail inbox. This function is essential for managing temporary email addresses and interacting with received messages programmatically.
Input Parameters
Parameter | Type | Description | Optional |
|---|---|---|---|
| String | The YOPmail email address (without the @yopmail.com domain). | No |
| Object | An object containing search criteria to filter emails. Supports exact matching for | Yes |
| Object | An object containing settings for inbox retrieval.
| Yes |
Purpose
The getInbox() function serves the following purposes:
Inbox Retrieval: It fetches the inbox contents of a specified YOPmail address, providing a list of emails received at that address.
Email Management: By accessing the inbox, developers can programmatically manage emails, enabling actions like reading, deleting, or filtering messages based on various criteria.
Automation:
getInbox()facilitates the automation of tasks involving temporary email addresses, such as collecting verification codes, monitoring for specific emails, or scraping data from received messages.
Functionality
The getInbox() function performs the following actions:
Request Inbox Data: It sends an HTTP GET request to the YOPmail server, targeting the inbox of the provided email address. This request includes essential parameters like the email address and pagination details.
Parse Inbox HTML: Upon receiving the server response, the function parses the HTML content of the inbox page. It extracts key information about each email, including the sender, subject, timestamp, and a unique identifier.
Structure Inbox Data: The extracted information is then organized into a structured JavaScript object. This object provides an overview of the inbox, including the total number of emails, pagination details, and an array of email objects, each representing a single email in the inbox.
Apply Filtering (Optional): The
getInbox()function can optionally accept asearchobject to filter retrieved emails. This filtering supports exact matches forid,timestamp, andday. Forfromandsubjectfields, it also provides a powerful partial matching capability using the%wildcard. This allows for flexible searches such as finding emails from a specific domain (%@example.com), emails with a subject containing a keyword (%keyword%), or emails starting with a certain phrase (prefix%).Return Inbox Object: Finally, the function returns the structured inbox object, containing all retrieved email information and relevant metadata.
Implementation
Here's an example demonstrating how to use getInbox() in your Node.js project:
Advanced Search with Wildcards
The search parameter offers powerful filtering capabilities, including the use of the % wildcard for partial matching in from and subject fields.
Filtering by Sender (from) with Wildcard
Filtering by Subject (subject) with Wildcard
Filtering by Day (day)
Controlling Retrieval and Order
The settings parameter offers three properties to control the retrieval process: LIMIT_PAGE, LIMIT_MAIL, and ORDER.
LIMIT_PAGEdetermines the maximum number of pages the function will explore.LIMIT_MAILspecifies the absolute maximum number of emails to return.ORDERcontrols the final sort order of the returned emails.
Using LIMIT_PAGE and LIMIT_MAIL
LIMIT_PAGE and LIMIT_MAIL work together to give you precise control. The function stops fetching when either limit is reached. LIMIT_PAGE takes precedence, setting a hard cap on the number of emails that can be fetched.
Ordering the Results with ORDER
By default, getInbox() returns emails in descending order ('desc'), from newest to oldest. You can change this by setting ORDER to 'asc'.
The ordering is applied after emails are fetched. If you request the 10 most recent emails (LIMIT_MAIL: 10) and set ORDER: 'asc', you will get those 10 emails sorted from the oldest among them to the newest.
Combining Search and All Settings
You can combine all parameters for highly specific queries:
Conclusion
The getInbox() function offers a versatile and efficient method to interact with YOPmail inboxes, empowering developers to automate tasks, manage temporary email addresses, and access received emails programmatically. By understanding its functionality and implementation, you can effectively leverage this tool in your Node.js projects.