Guerrilla Mail API Wrapper

1.2.2 · active · verified Wed Apr 22

A JavaScript promise-based wrapper for the Guerrilla Mail API, providing a convenient interface for programmatic interaction with temporary email addresses. This package, currently at stable version 1.2.2, simplifies common tasks such as registering new email addresses, fetching incoming mail, and managing inboxes. While there isn't an explicit release cadence stated, the project demonstrates active maintenance, as evidenced by its recent version tag and feature set. Key differentiators include its promise-based architecture leveraging Axios for robust HTTP requests, an integrated interval poller powered by `setinterval-plus` that offers methods like `start`, `stop`, `play`, and `pause` for managing email reception, and comprehensive event-driven communication via `EventEmitter3`. This event system emits crucial signals such as `emailAddress` upon successful address registration and `newEmail` when new messages arrive, streamlining asynchronous workflows. Furthermore, the wrapper abstracts away the internal handling of `sid_token`s, simplifying API calls for developers.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates instantiation of the GuerrillaMailApi wrapper, listening for the crucial `emailAddress` event, starting and stopping email polling, and handling incoming `newEmail` events.

import GuerrillaMailApi from 'guerrillamail-api';

async function main() {
  // Instantiate the API wrapper, optionally setting a custom user or polling interval.
  const GuerrillaApi = new GuerrillaMailApi({
    // Uncomment the line below to connect to a specific inbox username
    // emailUser: 'your_custom_username',
    // Set polling interval to 10 seconds (10000ms), default is 20 seconds
    pollInterval: 10000
  });

  console.log('Initializing Guerrilla Mail API wrapper...');

  // Crucially, wait for the 'emailAddress' event which signals API readiness.
  GuerrillaApi.on('emailAddress', (result) => {
    console.log(`Email address registered: ${result.email_addr}`);
    // Start polling for new emails only after an address is assigned.
    GuerrillaApi.pollStart();
    console.log('Started polling for new emails...');
  });

  // Listen for the 'newEmail' event when a message arrives.
  GuerrillaApi.on('newEmail', (email) => {
    console.log('\nNew email received!');
    console.log(`From: ${email.mail_from}`);
    console.log(`Subject: ${email.mail_subject}`);
    console.log(`ID: ${email.mail_id}`);
    // In a production scenario, you might then fetch the full email content:
    // GuerrillaApi.getEmail(email.mail_id).then(fullEmail => console.log(fullEmail.mail_body));
    
    // For this example, we'll stop polling after the first email.
    GuerrillaApi.pollStop(); 
    console.log('Polling stopped after receiving an email. Re-run the script to receive another.');
  });

  // Implement error handling for API or wrapper issues.
  GuerrillaApi.on('error', (err) => {
    console.error('An error occurred:', err);
  });

  // Keep the Node.js process alive to allow events to be emitted.
  // In a real-world application, this would be managed by a server or service lifecycle.
  await new Promise(resolve => setTimeout(resolve, 90000)); // Run for 90 seconds before exiting
  console.log('Quickstart example finished running after timeout.');
  GuerrillaApi.pollStop(); // Ensure polling is stopped on exit
}

view raw JSON →