Skip to main content

Use inbound TXT/SMS

MailSlurp supports creation and management of real mobile phone numbers in multiple regions. Phone numbers can receive inbound SMS text messages that can be read and received in code, tests, or online.

sms-basic

Common use for SMS includes testing OTP codes. See the tutorials for examples:

Creating phone numbers

First add a phone plan to your account subscription. Then provision a phone number for the plan in the MailSlurp dashboard or using the API.

Create in dashboard

To assign new phone number use the dashboard phone number page. You can select from a range of phone countries and pricing plans.

Create phone

Create phone number programmatically

To enable API phone creation you must first have a paid plan and enable API creation on the phone number overview page in the dashboard.

enable sms

Once enabled you can call the create phone number endpoints:

Loading...
info

Each create phone number call bills your account for a phone number rental of one month. This is because telecom providers only rent phone numbers for a minimum of one month.

Listing phone numbers

Phone numbers have an ID and a number. When fetching the phone number use the ID. Use the PhoneControllerApi to manage phone numbers.

Loading...

You can fetch numbers directly using the getBy methods:

Loading...

View SMS messages

In the dashboard you can view TXT message threads in the phones section:

View SMS

Use the SmsControllerApi to view and download SMS messages.

Loading...

You can fetch individual messages using the message's ID.

Loading...

Send SMS

You can send SMS programmatically or using the dashboard.

Loading...
info

Telecom providers impose some regulations on sending. Only send to numbers that have explicitly consented to being contacted. By default MailSlurp only permits sending to numbers that have initiated contact with you. To remove this restriction contact support.

Send a test message

You can instruct MailSlurp to send a test message to your phone number using the test messages:

Loading...

Wait for new SMS messages

Use the WaitForControllerApi waitForSms methods to hold a connection open until an expected count of SMS messages is present in a phone number

Loading...

This is an important technique for SMS based testing. See the testing guide for more information.

Use SMS webhooks

Have SMS messages sent via HTTP POST to your server with TXT Webhooks

Loading...