What you'll need
- A Mailosaur account or free trial account.
- An API key generated in your account.
- Knowledge of how to send emails (or SMS) into your account.
Express: Generate with a sample project
With npm installed, get started by generating a basic starter project for Playwright via the command line:
npm create mailosaur@latest
This gives you a simple Playwright project with Mailosaur pre-configured, along with some basic tests. You can also see sample code on GitHub.
Integrate into an existing Playwright project
With an existing Playwright project (or one you've just created), this is how to install and configure Mailosaur's API client library:
Install the API client
- Install the Mailosaur Node.js library:
npm install mailosaur
- Import the Mailosaur client into your test code:
const MailosaurClient = require("mailosaur");
// Find your API key at https://mailosaur.com/app/keys
const mailosaur = new MailosaurClient("API_KEY");
Make your first API call
// Make a simple API call to find the name of your inbox
const result = await mailosaur.servers.list();
console.log(`Inbox name is ${result.items[0].name}`);
Start testing
With a project connected to the Mailosaur API, you can start creating tests:
- Email testing - test password resets, account verification, order confirmations, etc.
- SMS testing - test alerts, notifications, and 2FA logins
- 2FA app testing - mimic the functionality of apps like Google Authenticator and 0Auth
- Email deliverability testing