EasyYopmail 5.0.0 Help

📑 readMessage()

The readMessage() function in Easy-Yopmail allows you to read the content of a specific email within a YOPmail inbox. It provides options to retrieve the content in plain text or HTML format, and even allows you to target specific elements within the email using CSS selectors.

Input Parameters

Parameter

Type

Description

mail

String

The YOPmail email address (without the @yopmail.com domain).

id

String

The unique ID of the email you want to read.

options

Object

(Optional) An object with additional options to customize the read operation.

Options within the options parameter:

  • format: (Optional) Format of the email content. Can be "TXT" (plain text) or "HTML" (HTML). Defaults to "TXT".

  • selector: (Optional) A CSS selector to target a specific element within the HTML email body.

  • attribute: (Optional) If a selector is provided, this parameter specifies the attribute of the element to be returned (e.g., "href" for a link).

  • pathToSave: (Optional) Path to save the email HTML as a file.

  • saveAttachments: (Optional) Boolean flag to save email attachments to the project download folder.

Output

The readMessage() function returns a promise that resolves with an object containing the following information:

  • id: The ID of the email.

  • submit: The subject of the email.

  • from: The sender's email address.

  • date: The date the email was received.

  • deliverability: Information about the email delivery.

  • attachments: An array of attachment objects (if saveAttachments is enabled).

  • saveAttachments: A boolean flag indicating if attachments were saved.

  • format: The format of the returned content ("TXT" or "HTML").

  • selector: The CSS selector used (if provided).

  • eq: The index of the selected element (if provided).

  • attribute: The attribute of the selected element (if provided).

  • pathToSave: The path where the HTML was saved (if provided).

  • content: The content of the email in the specified format.

  • info: A list of warnings or informational messages.

Mermaid Diagram

NodeJSEasyYopmailYopmailFileSystemalt[pathToSave option provided]readMessage(mail, id, options)Request email content by IDReturn email contentProcess email content (format, selector, attribute)Save email HTML to fileSave HTML contentNodeJSEasyYopmailYopmailFileSystem

Practical Use Cases

1. Read Plain Text Content of an Email

easyYopmail.readMessage('my-email', 'email-id') .then(message => { console.log(message.content); // Plain text content of the email });
easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', selector: 'a.confirmation-link', attribute: 'href' }) .then(message => { console.log(message.content); // URL of the confirmation link });

3. Save Full HTML Content of an Email to a File

easyYopmail.readMessage('my-email', 'email-id', { format: 'HTML', pathToSave: './emails' }) .then(message => { console.log('Email saved as HTML file'); });

4. Read Email Content and Save Attachments

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' } ]
image.png

Code Example

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 }); });
Last modified: 08 November 2024