MailSlurp logo

guides

Receive emails in code and tests.

How to fetch and parse emails and attachments in tests or code using MailSlurp email APIs, SMTP libraries, GraphQL and more.

For full documentation please see the receiving email guide.

Creating email addresses to receive emails

To read emails in code or tests the first step is to create an email address than can receive emails.

Configure an SDK client

Either use the SMTP settings with any SMTP client as shown below:

Or use one of many developer toolkits including the recommended NPM client.

  • npm install --save mailslurp-client

Import the client:

import { MailSlurp } from "mailslurp-client";

Then setup the client with an API Key.

const mailslurp = new MailSlurp({ apiKey: your_key_here });

Creating an inbox

Create an email address with a randomly assigned address:

const MailSlurp = require("mailslurp-client").default;
const mailslurp = new MailSlurp({
  apiKey: process.env.API_KEY ?? "your-api-key",
});

// create an inbox with options using the inbox controller
const inbox = await mailslurp.inboxController.createInbox({
  // name is used a contact name when sending
  name: "John Doe",
  // use the expanded domain pool so randomly assigned email address is more varied
  useDomainPool: true,
  // permanent by default or supply an expires at time
  expiresAt: undefined,
});

Receive email

Once you have created an inbox send an email to it from your own email client, using the SDK client, or using the MailSlurp dashboard.