Skip to main content
coreydaley.dev

How to test SMS locally: a Mailpit for text messages

To test SMS locally, point your app’s Twilio client at a local server that accepts the same API and shows you what was “sent”. Nothing reaches a real phone, nothing is charged, and you can read every message, the way Mailpit catches email in development.

Mailpit itself only does email. For text messages you have two practical options.

Option 1: catch the messages locally (MessagePit)

MessagePit is my open-source fork of Mailpit that adds a Twilio-compatible SMS endpoint. Your app sends exactly the request it would send to Twilio; MessagePit stores it and shows it in an SMS tab next to the email inbox.

PortWhat it’s for
8025The web inbox (email and SMS)
8200SMS: accepts Twilio’s POST /2010-04-01/Accounts/{AccountSid}/Messages.json
1025Email over SMTP, as in Mailpit

Run it with Docker (see Getting started for the other ways to install it), then send it a message the way Twilio’s API would receive one:

curl -u ACtest:testtoken \
  -X POST http://localhost:8200/2010-04-01/Accounts/ACtest/Messages.json \
  --data-urlencode From=+15005550006 \
  --data-urlencode To=+15551234567 \
  --data-urlencode "Body=Your code is 123456"

It answers like Twilio does, with "status": "queued", and the message appears in the inbox at http://localhost:8025. The username and password are your Account SID and auth token. MessagePit accepts any credentials unless you set MP_TWILIO_AUTH_TOKEN; set it to the token your app sends if you want a wrong token rejected.

In your app, the change is the API host: send Twilio requests to http://localhost:8200 instead of https://api.twilio.com. How you set that depends on your Twilio library; the Rails example shows it for twilio-ruby. The SMS docs also cover signed delivery callbacks; test numbers that trigger delivery failures are coming in the next release.

Option 2: Twilio’s test credentials

Twilio accounts created in its older console have test credentials: a separate Account SID and auth token that call the real API but never send a message or charge you. Twilio says they can’t be created in its new console, so newer accounts may not have this option. Special “magic” numbers return set results, such as +15005550006 as a valid sender.

This checks that your requests are well formed, but there’s no inbox: you see the API’s response, not the message, and test credentials don’t fire status callbacks either. It’s useful in CI; less so when you want to read the text a user would get.

Which to use

  • Reading what your app sends (wording, codes, links, how many messages a flow produces): catch them locally.
  • Checking requests against Twilio’s real validation: Twilio’s test credentials.
  • Before going live: send a few real messages to your own phone with your live credentials. Neither option above shows carrier delivery.

I tested the MessagePit request above on macOS 27, building MessagePit from its current source.