Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

mailslurp-client

8.7.8 • Public • Published

MailSlurp Javascript Client

Create real email addresses on demand. Send and receive emails and attachments from code and tests using Javascript or Typescript.

MailSlurp is an email API service that let's you create real email addresses in code. You can then send and receive emails and attachments in Javascript applications and tests.

Get started

First you'll need an API Key. Create a free account and copy they key from your dashboard.

Install NPM dependency

npm install --save mailslurp-client

Import MailSlurp

const MailSlurp = require("mailslurp-client").default;
 
// or
 
import { MailSlurp } from "mailslurp-client";

Instantiate a client

Create a MailSlurp instance by instantiating a class with your API Key.

const mailslurp = new MailSlurp({ apiKey: "your_api_key" })

Common use case examples

For all the MailSlurp features please see the method documentation included with this project.

Create an email address

const inbox = await mailslurp.createInbox()
// { id: '123', emailAddress: '123@mailslurp.com' }

Fetch emails from inbox

There are many ways to receive and fetch emails in MailSlurp.

const latestEmail = await mailslurp.waitForLatestEmail(inbox.id)
 
expect(latestEmail.subject).toContain("Hello")
expect(latestEmail.body).toContain("Welcome")
 
 
const secondEmail = await mailslurp.waitForNthEmail(inbox.id, 1)
const allEmails = await mailslurp.getInboxEmailsPaginated(inbox.id)

Send emails

const options = {
    to: ['test@myemail.com'],
    subject: 'Hello',
    body: 'Welcome'
}
await mailslurp.sendEmail(inbox.id, options)

Documentation

Resources

Install

npm i mailslurp-client

DownloadsWeekly Downloads

4,150

Version

8.7.8

License

MIT

Unpacked Size

1.16 MB

Total Files

30

Last publish

Collaborators

  • avatar