MailSlurp's dashboard and API help teams retrieve and extract content from delivered emails.

Use this guide when you need to:

- read the body of an email in code
- extract verification codes, OTPs, and magic links
- find links in HTML email bodies
- match expected text in transactional messages
- send extracted content into tests, webhooks, or downstream workflows

For terminology and testing guidance, start with [What is the body of an email?](/guides/body-of-an-email/).

## Quick answer

Use MailSlurp to receive the real email, then read or match the delivered body.

The usual workflow is:

1. create or use a MailSlurp inbox
2. trigger the app workflow that sends the email
3. wait for the matching message
4. inspect the plain text or HTML body
5. extract the code, link, amount, order ID, or other value
6. submit that value back into the test or automation flow

This is stronger than checking that the application attempted to send an email. It proves the content arrived and can be used.

## Extract body content

You can use the EmailController `getEmailContentMatch` method to extract matching text from an email.



```typescript
it("get email content", async () => {
  const mailslurp = new MailSlurp(config);

  const inbox1 = await mailslurp.createInbox();
  const inbox2 = await mailslurp.createInbox();

  const to = [inbox2.emailAddress!];
  const body = "Hi there. Your code is: 123456";
  await mailslurp.sendEmail(inbox1.id!, { to, body });

  // wait for email
  const email = await mailslurp.waitController.waitForLatestEmail({
    inboxId: inbox2.id,
    timeout: timeoutMillis,
    unreadOnly: true,
  });
  const pattern = "code is: ([0-9]{6})";
  expect(email.body).toContain("Your code is");

  const result = await mailslurp.emailController.getEmailContentMatch({
    contentMatchOptions: { pattern },
    emailId: email.id!,
  });
  expect(result.matches).toHaveLength(2);
  expect(result.matches[0]).toEqual("code is: 123456");
  expect(result.matches[1]).toEqual("123456");
  // now do something with the code
});
```



Use [MailSlurp APIs](/api/) in any language with the [official SDKs](/developers/) or inspect received messages in the [web app](https://app.mailslurp.com/).

## Match email fields before reading the body

Before extracting the body, filter for the correct email. For example, send a verification email with a code you want to extract:



```typescript
const inboxController = new InboxControllerApi(new Configuration({ apiKey }));
const inbox = await inboxController.createInbox({});
await inboxController.sendEmail({
  inboxId: inbox.id!,
  sendEmailOptions: {
    to: [inbox.emailAddress!],
    subject: "Verification code",
    html: true,
    body: 'Here is <a href="https://test.com/verfiy?code=123">your code</a>',
  },
});
```



We can use `waitForMatchingFirstEmail` methods to extract the code.



```typescript
const waitForController = new WaitForControllerApi(new Configuration({ apiKey }));
const confirmation = await waitForController.waitForMatchingFirstEmail({
  inboxId: inbox.id,
  unreadOnly: true,
  timeout: 30000,
  matchOptions: {
    // pass an array of MatchOption items
    matches: [
      {
        field: MatchOptionFieldEnum.SUBJECT,
        should: MatchOptionShouldEnum.CONTAIN,
        value: "Verification code",
      },
    ],
  },
});
// use a regex in code to extract the content
const r = /href="(https[^"]+)"/gs;
const results = r.exec(confirmation.body!!)!!;
const url = decodeURIComponent(results[1]);
// now you can use the verification code
expect(url).toBeTruthy();
```



### Match definitions

Here are the fields and `should` options that can be used when matching emails:

```typescript
export enum MatchOptionFieldEnum {
  SUBJECT = "SUBJECT",
  TO = "TO",
  BCC = "BCC",
  CC = "CC",
  FROM = "FROM",
}
export enum MatchOptionShouldEnum {
  CONTAIN = "CONTAIN",
  EQUAL = "EQUAL",
}
```

## Find links in email bodies

Use the `getEmailLinks` method on the EmailController to parse emails and extract HTML links.



```typescript
test("can extract email links", async () => {
  const mailslurp = new MailSlurp({ apiKey });
  // send html email to inbox 1 containing a link
  const inbox = await mailslurp.createInbox();
  const href = "https://test.com?code=123";
  const body = '<html><body><p>Here is <a href="' + href + '">your link</a></p></body></html>';
  await mailslurp.sendEmail(inbox.id!!, {
    to: [inbox.emailAddress!!],
    body,
    isHTML: true,
  });
  // can get link from email
  const email = await mailslurp.waitForLatestEmail(inbox.id!!, 60000, true);
  const linkResult = await mailslurp.emailController.getEmailLinks({
    emailId: email.id!!,
  });
  expect(linkResult.links).toEqual([href]);
});
```



This is useful for:

- password reset links
- email confirmation links
- magic-link login
- invite acceptance links
- billing or approval links

If you have trouble with strict matches, first assert the content of the received email using less strict `waitForLatestEmail` methods, then tighten the filters once you know the message shape.

## What to extract from the email body

| Workflow            | Content to extract                               | Next action                                |
| ------------------- | ------------------------------------------------ | ------------------------------------------ |
| Signup confirmation | OTP code or verification link                    | Submit code or open link in the test       |
| Password reset      | Reset link and expiry text                       | Validate reset flow and timeout behavior   |
| Invoice email       | Total, due date, invoice number, attachment name | Store or route the structured data         |
| Support email       | Reply body, ticket ID, attachment references     | Create or update the support record        |
| Campaign QA         | CTA links, unsubscribe link, footer text         | Verify body content before sending broadly |

For structured operational data, use [AI email parsing and structured extraction](/product/ai-email-parsing-structured-content-extraction/) or the broader [Extract platform](/product/extract/).

## Related pages

- [Body of an email](/guides/body-of-an-email/)
- [Email integration testing](/product/email-integration-testing/)
- [Authentication testing](/solutions/authentication-testing/)
- [Email webhooks](/guides/email-webhooks/)
- [Extract platform](/product/extract/)

## More examples

Find more source code in the [examples section](/examples/) or the [guides page](/guides/).
