# Test email processes

One major MailSlurp use case is testing email content and email dependent processes.

# Write automated tests

You can use MailSlurp's REST API or SDK libraries to write automated tests using real email addresses. For example you could test critical email processes in your application like user sign-up and verification. Here is what that might look like:

// test app sign-up using a randomly allocated email address
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);

# Review email content

You can use the MailSlurp UI to view HTML email previews, download attachments, and check spam analysis verdicts.

analysis


# Send emails

Compose emails with templates and attachments. Send from applications and tests with full control over headers, domains, and content-types.

# Send emails and attachments in code and tests

REST API and libraries available in several languages.

// upload attachments to mailslurp
const file = fs.readFileSync(path);
const [id] = await api.uploadAttachment({
  base64Contents: new Buffer(file).toString("base64"),
  filename: "",
  contentType: ""
});

// attach the files with id to send
api.sendEmail(inbox.id, {
  to: ["user@example.org"],
  subject: "Hello {{name}}",
  body: "Dear {{name}}, your code is {{code}}.",
  templateVars: {
    name: "",
    code: ""
  },
  attachments: [id]
});

# Compose emails in visual dashboard

Team access to a visual editor for composing and sending emails.

analysis


# Receive and respond to emails

# Fetch emails in code or receive via webhooks

Get emails with search queries and long-polling.

// fetch emails directly
const { id, subject, body, attachments } = await mailslurp.waitForLatestEmail(
  inbox.id
);

Or recieve emails directly on your server via webhook push events.

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

# Web interface for HTML previews and attachment downloads

Verify email content and view attachments online.

emails


# Empower teams

MailSlurp scales with your needs. Built on secure cloud infrastructure, MailSlurp offers team access and high throughput APIs for automated testing and CI pipelines.