MailSlurp Use Cases: Email Testing, Sending, and Receiving
MailSlurp lets you create real email addresses on demand with a visual dashboard, REST API and SDKs in several languages.
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 timeout = 60000;
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, timeout);
// 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.
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(pathToAttachment);
const [id] = await mailslurp.uploadAttachment({
base64Contents: file.toString('base64'),
filename: 'test.txt',
contentType: 'plain/text',
});
// attach the files with id to send
await mailslurp.sendEmail(sendInbox.id!, {
to: [testInbox.emailAddress!],
subject: 'Hello {{name}}',
body: 'Dear {{name}}, your code is {{code}}.',
templateVariables: {
name: 'user',
code: '123456',
} as any,
attachments: [id.toString()],
});
Compose emails in visual dashboard
Team access to a visual editor for composing and sending emails.
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, timeout);
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.
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.