Email REST API Documentation

Test email account generation API for MailSlurp. Rest API documentation for HTTP email clients. Get a free API Key.

MailSlurp is an email platform for developers, social teams and QA testers. Use MailSlurp's APIs with REST, SMTP, and GraphQL to create email addresses on demand and send and receive emails.

REST API resources

MailSlurp API features

MailSlurp is an email platform for developers and QA testers. IT lets you send and receive emails in a wide range of protocols and programming languages including GraphQL, SMTP, C#, Java, NodeJS, PHP, Ruby, and more.

Example use cases

You can use MailSlurp with any language using the REST API or the recommend Javascript client.

To setup the SDK create an account the run npm install --save mailslurp-client

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

// create a client
const apiKey = process.env.API_KEY ?? 'your-api-key';
const mailslurp = new MailSlurp({ apiKey });

// create an inbox
const inbox = await mailslurp.inboxController.createInbox({});
expect(inbox.emailAddress).toContain('@mailslurp');

Test applications end-to-end with disposable email addresses

Send transactional email campaigns

Receive and respond to inbound SMS and emails

To wait for expected emails to arrive and read their contents use the WaitFor controller endpoints.

// first wait for an email
const email = await mailslurp.waitController.waitForLatestEmail({
  inboxId: inboxId,
  timeout: 30000,
  unreadOnly: true,
});

// check has attachments
expect(email.attachments.length).toEqual(1);

// download with email controller as base64 string
const attachmentDto =
  await mailslurp.emailController.downloadAttachmentBase64({
    attachmentId: email.attachments[0]!!,
    emailId: email.id,
  });

// can access content
expect(attachmentDto.base64FileContents).toBeTruthy();
const fileContent = new Buffer(
  attachmentDto.base64FileContents,
  'base64'
).toString();
expect(fileContent).toContain('test');

// can access size etc
expect(attachmentDto.sizeBytes).toBeTruthy();
expect(attachmentDto.contentType).toBeTruthy();

Related content

Email REST API Documentation

Test email account generation API for MailSlurp. Rest API documentation for HTTP email clients. Get a free API Key.

Ready to dive in?Start building email applications today.