4.0.1 • Published 4 years ago

@researchgate/emailonacid-client v4.0.1

Weekly downloads
41
License
MIT
Repository
-
Last release
4 years ago

Email-On-Acid Client

This modules is a client for Email on Acid service for testing emails.

Environment requirements

This module works in Node and Web environments

This module requires Node 7.6.0+ because of async/await syntax. For the browser, make sure to polyfill Promise, transpile arrow functions and async/await syntax. This module also includes fetch and atob/btoa API polyfills to be server- & client- side ready.

Installation

# yarn
yarn add @researchgate/emailonacid-client

# npm
npm install --save @researchgate/emailonacid-client

Usage

const createClient = require('@researchgate/emailonacid-client');

/**
 * Make sure to catch rejections from client
 */
try {
  /**
   * Create a new client instance, this will validate credentials as well.
   * Please note that every API method is async and returns a Promise.
   *
   * It is recommended to store API Key and Account Password in env variables
   * for security reasons. Check `dotenv` module for comfortable env vars management.
   */
  const client = createClient({
    // Required, your API Key
    apiKey: process.env.EOA_API_KEY,
    // Required, your account password
    accountPassword: process.env.EOA_ACCOUNT_PASSWORD,
    // Optional, base Rest API URL. Defaults to value below.
    apiBaseUrl: 'https://api.emailonacid.com/v5',
    // Optional, list of clients to test. Defaults to value below.
    clients: ['iphone6p_9', 'gmail_chr26_win', 'outlook16'],
  });
  /**
   * Example: creating new test.
   * Tests are stored for 90 days and would resolve previous (if any) cached result
   * if all options are same. Mails sent via utf8 encoding.
   */
  const freshlyCreatedTest = await client.createTest({
    // Required, mail's subject to test
    subject: 'Hello'
    // Required, mail's markup
    html: '<p>Hello there</p>',
    // Optional, flag to block images or not. Defaults to value below.
    shouldBlockImages: false,
  });
  console.log(freshlyCreatedTest.id); // -> unqie id generated by EmailOnAcid
} catch (error) {
  console.error(error);
}

This module also keeps static information about list of available clients. Please keep in mind that it's collected on publish step and might be out-of-date.

const { clients } = require('@researchgate/emailonacid-client');
console.log(clients); // <- array with available clients

Testing

yarn test

Publishing

yarn publish