Test SMS phone numbers are important for communication purposes.
Read text messages in code and webhooks to test applications and authentication end-to-end. Real phone numbers for developers and QA testers.
Create real phone numbers in multiple regions and receive inbound SMS/TXT messages in code and tests.
Features
MailSlurp's phone packages allow for many possibilities when developing and testing SMS reliant applications.
- Create real phone numbers on demand (USA, UK and more).
- Receive SMS/TXT messages
- Webhook notifications for inbound SMS
Wait for
SMS matching methods- Test 2FA/OTP SMS authentication
Dashboard settings
Phone numbers and SMS can be views and configured in the online dashboard or using API clients in any framework.
Creating phone numbers
You can create real phone numbers with SMS ability using the MailSlurp dashboard. Clicking create will open the billing portal to confirm the payment options for the given phone number.
Phone numbers are billed monthly as a line rental. Each phone also has an associated phone plan that bills for inbound SMS usage. For more information see the pricing page.
Manage phone numbers
You can fetch and list phone numbers using the phone number controller in any client or using the REST API. Below is an example using the official Javascript library.
const mailslurp = new MailSlurp({ apiKey });
// fetch a phone number (must create phone numbers in the dashboard first)
const {
content: [phoneNumber],
} = await mailslurp.phoneController.getPhoneNumbers({
size: 1,
phoneCountry: GetPhoneNumbersPhoneCountryEnum.US,
});
expect(phoneNumber.phoneNumber).toEqual('+19108074451');
Wait for new SMS
Use the WaitController to hold a connection until an SMS condition is met. Here we can see how to wait for the latest unread SMS to be received in a phone number. Waiting for SMS with a method allows you to test asynchronous SMS features in your application. See the SMS usage guide to get started.
// wait for the latest unread sms
const [sms] = await mailslurp.waitController.waitForSms({
waitForSmsConditions: {
count: 1,
unreadOnly: true,
phoneNumberId: phoneNumber.id,
timeout: 30_000,
},
});
// extract a code from body with regex
expect(sms.body).toContain('Your code: 123');
const [, code] = /.+:\s([0-9]{3})/.exec(sms.body);
expect(code).toEqual('123');
Fetch SMS message
To read text messages fetch them by ID or use wait methods or webhooks.
// fetch a message
const txtMessage = await mailslurp.smsController.getSmsMessage({
smsId: sms.id,
});
expect(txtMessage.read).toEqual(true);
expect(txtMessage.fromNumber).toEqual('+13252527014');
// delete all messages in phone number
await mailslurp.smsController.deleteSmsMessages({
phoneNumberId: sms.phoneNumber,
});
SMS webhooks
Use webhooks to have SMS/TXT messages routed directly to your server using HTTP/S.
// create a webhook for a phone number to have new SMS sent to your server
const webhook =
await mailslurp.webhookController.createWebhookForPhoneNumber({
phoneNumberId: phoneNumber.id,
createWebhookOptions: {
eventName: CreateWebhookOptionsEventNameEnum.NEW_SMS,
url: 'https://myserver.com',
name: 'Process SMS',
},
});
See the webhook documentation for more information.
Getting started
Create a free account to get started or see the developer guide for tutorials and examples of SMS usage in multiple languages.