# 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 lets you create real email addresses in code. You can then send and receive emails and attachments in Javascript applications and tests.

# Get started

TIP

This section describes how to get up and running with the Javascript client.

See the guides page for more examples and use with common frameworks.

See the method documentation for a list of all functions

# Create API Key

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

# Install NPM dependency

Install MailSlurp using NPM (NodeJS) or by including the source code in your project.

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 usage

Here are some snippets of common usage. Read

# Create an email address

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

See method documentation for a list of all functions.

# 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