npm

Join us for the "JavaScript Supply Chain Security" tech talk, presented by VP of Security, Adam Baldwin. 6/20 at 10am PT.Sign up here »

mailslurp-client

3.0.14 • Public • Published

Official MailSlurp Javascript/Typescript API Client

Offical SDK Client for the MailSlurp API. See https://www.mailslurp.com for more information.

Completely rewritten for MailSlurp v2.0.

About

This client is a handwritten wrapper around the official generated swagger client. It's written in Typescript but can be used in Javascript.

Concept

MailSlurp is an API for sending and receiving emails from ephemeral addresses. It is designed for use in test suites that test applications that in some way interact with emails.

Below is a diagram of how your application, tests and MailSlurp interact. MailSlurp Concept

Documentation

Start by reading the the official MailSlurp documentation.

The best way to understand this library is the examples section.

The source for this client is very small so try reading index.ts Typescript definitions. Or additionally take a look at the js-docs.

Install

npm install mailslurp-client OR yarn add mailslurp-client

Usage

Instantiation

// import the package
import MailSlurp from "mailslurp-client"
// const MailSlurp = require("mailslurp-client")
 
// create an instance with your apiKey
const api = new MailSlurp({ apiKey: "test" })

Methods

interface AbstractMailSlurpClient {
    getEmail(emailId: string): Promise<Email>;
 
    createInbox(): Promise<Inbox>;
 
    deleteInbox(inboxId: string): Promise<Response>;
 
    getInbox(inboxId: string): Promise<Inbox>;
 
    getInboxes(): Promise<Inbox[]>;
 
    getEmails(inboxId: string, args: GetMessagesOptions): Promise<EmailPreview[]>;
 
    sendEmail(inboxId: string, sendEmailOptions: SendEmailOptions): Promise<Response>
}
 

Response types

See documentation for more information.

Examples

Test email sending

// javascript jest example. other SDKs and REST APIs available
import { MailSlurp } from "mailslurp-client"
const api = new MailSlurp({ apiKey: "test" }) 
 
test('my app can receive and handle emails', async () => {
    // create a new email address for this test
    const inbox = await api.createInbox()
 
    // send an email from the address to your application
    await api.sendEmail(inbox.id, { to: myAppAddress })
 
    // assert that app has handled the email
    expect(myAppReceivedEmail()).resolves.toBe(true)
})

Test email processing

// can your app handle inbound emails
import { MailSlurp } from "mailslurp-client"
const api = new MailSlurp({ apiKey: "test" }) 
 
test('my app can send emails', async () => {
    // create a new email address for this test
    const inbox = await api.createInbox()
 
    // trigger an app action that sends an email
    await signUpForMyApp(inbox.emailAddress)
 
    // fetch welcome email from the inbox
    const emails = await api.getEmails(inbox.id, { minCount: 1 })
 
    // assert that the correct email was sent
    expect(emails[0].length).toBe(1)
    expect(emails[0].content).toBe(expectedContent)
}

For all functions and operations see the typescript definitions or developer documentation.

Debug

The library uses the debug package to log actions. Set DEBUG=mailslurp-client to enable logging output.

Keywords

none

install

npm i mailslurp-client

Downloadsweekly downloads

798

version

3.0.14

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability