# Email APIs for developers

TIP

What to jump in? Checkout the API documentation or the getting started guide.

MailSlurp was created as an email API that goes beyond traditional SMTP limitations.

MailSlurp is made for developers as an flexible MailServer with a REST API (opens new window), a browser-based web-app (opens new window), and programmatic SDKs built several languages. It is a hosted cloud service that is free for personal use.

You can use

# Features

A simple buit powerful HTTP REST API plus official libraries in Javascript, Python, PHP, Java, Golang, Ruby, Objective C, and C# / DotNet.

MailSlurp has lots of [documentation], [example projects], and [guides] to help you and your team get started quickly with modern email APIs.

# Email addresses on demand

Create new private email addresses on demand from applications or tests. (Examples in Javascript but available in all languages.)

// create a randomly assigned email address
const inbox = await mailslurp.createInbox();
console.log(inbox.emailAddress);
// create a custom email address with your own domain
const customInbox = await mailslurp.createInbox("user@mydomain.com");

# Fetch emails in code

Receive emails directly in tests or applications.

// hold connection open until first email found or timeout
const email = await mailslurp.waitForLatestEmail(inbox.id);
console.log(email.subject, email.body, email.attachments);
// more examples
const nthEmail = await mailslurp.waitForNthEmail(inbox.id, index);
const emails = await mailslurp.waitForEmailCountinbox(inbox.id, count);

# Use pattern matching

Search for emails matching field or body conditions. Use email with powerful helper functions.

// fetch in tests
const welcomeEmails = await mailslurp.waitForMatchingEmails(
  {
    matches: [
      {
        field: "SUBJECT",
        should: "CONTAIN",
        value: "Welcome",
      },
    ],
  },
  count,
  inbox.id
);

# Extract content and verify

You can use MailSlurp to extract email contents and attachments for use in tests or email processing pipelines.

const testInbox = await mailslurp.createInbox();
const user = await myApp.signUp(testInbox.emailAddress);
// verify that confirmation email was sent by your app
const email = await mailslurp.waitForLatestEmail(testInbox.id);
// confirm the user using the code
const [_, verificationCode] = /your code is "([0-9]{6})"/g.exec(email.body);
// do something with code like verifying an account
await myApp.confirmUser(verificationCode);

# Send email attachments

Easily send attachments and emails in code without SMTP setup.

// upload attachments to mailslurp
const file = fs.readFileSync(path);
const [id] = await mailslurp.uploadAttachment({
  base64Contents: new Buffer(file).toString("base64"),
  filename: "",
  contentType: "",
});
// attach the files with id to send
mailslurp.sendEmail(inbox.id, {
  to: ["test@example.org"],
  attachments: [id],
});

# Scales with your business

MailSlurp is a cloud based distributed system that uses message queues to safely process messages.

# WebHook queues

TIP

Please see the webhook usage guide for more information about webhooks.

Have received messages sent directly to your server in a queue system using webhooks. Backed by a powerful cloud queue MailSlurp will POST an email summary to your webhooks URL via HTTP whenever an email is received.

// get messages sent to your server
@PostMapping("/inbound-emails")
fun receiveEmails(emailEvent: Map<String,String>) {
    // respond to event
    mailSlurp.getAttachments(emailEvent["id"])
}

MailSlurp retries your webhook with a backoff for up to 24 hours and maintains a dead-letter queue.

# Send templated emails

Send HTML emails with Handlebars templating support.

mailslurp.sendEmail(inbox.id, {
  to: ["user@example.org"],
  subject: "Hello {{name}}",
  body: "Dear {{name}}, your code is {{code}}.",
  templateVars: {
    name: "",
    code: "",
  },
});

# Teams and admins

MailSlurp has pricing plans for enterprise usage (opens new window) and team access.

Manage your API usage and team access with our online dashboard.

ui