1.0.0 • Published 4 years ago

@lu-development/gmwrapper v1.0.0

Weekly downloads
1
License
ISC
Repository
bitbucket
Last release
4 years ago

gmWrapper

This module is a simple wrapper for the Guerillamail API.

Features

  • Programmatically access a disposable but persistent inbox
  • Set email username (different domains are not supported yet with this package)
  • Manage multiple email sessions as objects
  • Send, receive and delete emails

Please use this package responsibly, and checkout the project that inspired this wrapper!

Installing

Using npm:

$ npm install @lu-development/gmwrapper

Examples

Note: In order for the session to work, the establishSession() function must resolve. Because of the requests to the guerilla mail api, most functions return promises.

Checking an inbox using async/await:

const {gmSession} = require('@lu-development/gmwrapper')
async function () {
    let session = new gmSession()
    await session.establishSession()
    let inbox = await session.checkEmail()
}

Checking an inbox using promise chaining:

function () {
    let session = new gmSession()
    session.establishSession().then(() => {
        session.checkEmail().then((inbox)=> {
            console.log(inbox)
        })
    });
}

Setting a username:

async function () {
    let session = new gmSession()
    await session.establishSession()
    await session.setEmail('newusername')
}

//Optionally usernames can be set in the constructor
async function () {
    let session = new gmSession('username')
    await session.establishSession()
}

gmWrapper API

session.establishSession()

This function is required to start the session. Returns the session ID.

session.setEmail(emailUser)

Sets the username for the email. Returns the username.

session.checkEmail()

Checks the inbox for the session. Returns an array of email objects.

session.deleteEmail(email)

Deletes an email from the inbox, and requires the email object as an argument. Returns the response from the endpoint.

session.findEmailBySender(senderAddress[, timeout[, interval]])

Searches the inbox for an email by the sender address. Returns the email object.

session.findEmailBySubject(subject[, timeout[, interval]])

Searches the inbox for an email by the email subject. Returns the email object.

session.fetchEmail(emailID)

Queries for an email based on the email ID. Returns the email object.

session.getEmailAddr()

Returns the actual address for the inbox.

session.getAlias()

Returns an alias to conceal the address for the inbox.

session.getSid()

Returns session ID.

Sending Emails

The sending of emails is handled through a seperate object called the gmSender. It can be called like this:

sender.sendEmail(recipient, subject, body)

Sends an email from the session to the recipient.

const {gmSender} = require('@lu-development/gmwrapper')
async function () {
    let sender = new gmSender('myemail@gmail.com', 'password')
    await sender.sendEmail('otherTestUser@sharklasers.com', 'This is the subject', 'This is the body')
}
1.0.0

4 years ago