Send SMS From Ruby Without a Twilio Account
To send an SMS from Ruby you make one authenticated HTTP request. With SMSNET that request makes your own Android phone send the text, so there is no provider account and no number to rent.
What do I need before the first call?
Two things: a connected phone and an API key. Install the SMSNET Gateway app on any Android 8.0 or newer phone with a SIM, sign in, and the last screen of setup shows your key once. The Android gateway guide shows every screen. Put the key in an environment variable or Rails credentials; it can be rotated from the Developers page if it ever leaks.
The free plan is enough to build against: 300 messages a month, 20 a day, and replies are never counted. Recipients go in E.164 format (+15551234567), and the person you are texting should have agreed to hear from you.
How do I send an SMS with Net::HTTP?
require "net/http"
require "json"
require "uri"
module Smsnet
class Client
API_BASE = "https://smsnet.net/api/v1".freeze
TIMEOUT = 15
class Error < StandardError; end
def initialize(api_key = ENV["SMSNET_API_KEY"])
@api_key = api_key || raise(Error, "SMSNET_API_KEY not set")
end
def send(to:, body:, transactional: false)
uri = URI("#{API_BASE}/messages/send")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.open_timeout = TIMEOUT
http.read_timeout = TIMEOUT
request = Net::HTTP::Post.new(uri)
request["X-API-Key"] = @api_key
request["Content-Type"] = "application/json"
request.body = { to: to, body: body, transactional: transactional }.to_json
response = http.request(request)
handle_response(response)
end
private
def handle_response(response)
case response
when Net::HTTPSuccess
JSON.parse(response.body, symbolize_names: true)
when Net::HTTPBadRequest, Net::HTTPUnauthorized, Net::HTTPForbidden, Net::HTTPTooManyRequests
body = JSON.parse(response.body, symbolize_names: true) rescue { error: response.body }
raise Error, "SMSNET #{response.code}: #{body[:error] || 'request failed'}"
else
raise Error, "SMSNET #{response.code}: #{response.message}"
end
end
end
end
# Usage
client = Smsnet::Client.new
result = client.send(to: "+15551234567", body: "Your table is ready. Reply STOP to opt out.")
puts "Message ID: #{result[:message_id]}, Day quota: #{result.dig(:quota, :day, :used)}/#{result.dig(:quota, :day, :limit)}"
A successful response looks like this:
{
"ok": true,
"message_id": "msg_01j9x8k2...",
"conversation_id": "conv_01j9x8k2...",
"device_id": "dev_01j9x8k2...",
"quota": {
"month": { "used": 13, "limit": 300 },
"day": { "used": 4, "limit": 20 }
}
}
quota is there so your script can slow down before it hits the wall instead of discovering it as a 429. The limit has a fifth of headroom above it; once you are in that band the response carries "grace": true and a note.
Set transactional: true only for a message the recipient is waiting on right now, such as a login code. It skips the queue's pacing gap and quiet hours and reaches the phone in about a second, while still respecting the daily ceiling and the warmup ramp on a new line.
How do I send an SMS from Rails?
Add the client to your Rails app:
# app/services/smsnet/client.rb
module Smsnet
class Client
# ... (same as above)
end
end
# config/initializers/smsnet.rb
Rails.application.config.smsnet_client = Smsnet::Client.new(Rails.application.credentials.smsnet_api_key)
Send from a controller or job:
class OrdersController < ApplicationController
def create
@order = Order.create!(order_params)
Smsnet::Client.new.send(
to: @order.customer_phone,
body: "Your order ##{@order.id} is confirmed. Reply STOP to opt out."
)
head :ok
end
end
How do I read replies in Ruby?
Two options. Polling needs no public URL and suits a cron job or background worker; a webhook suits a web app.
Polling uses the message feed with a cursor. The first call without since returns the latest messages; every call after that passes back next_cursor, so nothing is missed or repeated even when several messages share a millisecond.
def poll_inbound(since = nil)
uri = URI("#{API_BASE}/messages")
uri.query = URI.encode_www_form(direction: "inbound", limit: 100, since: since).presence
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.open_timeout = TIMEOUT
http.read_timeout = TIMEOUT
request = Net::HTTP::Get.new(uri)
request["X-API-Key"] = @api_key
response = http.request(request)
handle_response(response)
end
For a webhook, register your HTTPS endpoint once (PUT /api/v1/webhooks with {"url": "..."}) and keep the secret from the response. SMSNET then POSTs message.received and message.status events, signs each one, and retries nine times over about three days if your endpoint is down. Verify the signature before trusting anything:
# config/routes.rb
post "/sms/webhook", to: "sms_webhook#receive"
# app/controllers/sms_webhook_controller.rb
class SmsWebhookController < ApplicationController
skip_forgery_protection
def receive
ts = request.headers["X-SMSNET-Timestamp"]
sig = request.headers["X-SMSNET-Signature"]
delivery = request.headers["X-SMSNET-Delivery"]
head :bad_request and return if ts.blank? || sig.blank?
head :bad_request and return if (Time.now.to_i - ts.to_i).abs > 300
raw = request.raw_post
expected = "v1=" + OpenSSL::HMAC.hexdigest("SHA256", secret, "#{ts}.#{raw}")
head :bad_request and return unless ActiveSupport::SecurityUtils.secure_compare(expected, sig)
# Dedupe on delivery (use Redis, DB, or Rails.cache)
# return head :ok if Rails.cache.exist?("smsnet:delivery:#{delivery}")
# Rails.cache.write("smsnet:delivery:#{delivery}", true, expires_in: 24.hours)
event = JSON.parse(raw, symbolize_names: true)
case event[:event]
when "message.received"
Rails.logger.info "SMS from #{event.dig(:data, :from)}: #{event.dig(:data, :body)}"
when "message.status"
Rails.logger.info "Message #{event.dig(:data, :message_id)} is now #{event.dig(:data, :status)}"
end
head :ok
end
private
def secret
Rails.application.credentials.smsnet_webhook_secret || ENV["SMSNET_WEBHOOK_SECRET"]
end
end
The signed material is the timestamp, a dot, and the raw request body, so verify against request.raw_post before anything parses it. Dedupe on the X-SMSNET-Delivery header, which is stable across retries. Send yourself a test event with POST /api/v1/webhooks/test before any real traffic exists.
What errors should the script expect?
| Status | When | What to do |
|---|---|---|
| 400 | Missing to or body, or no phone connected to the account | Fix the request, or connect a phone |
| 401 | Missing or wrong key; the error says whether the key was rotated | Load the key from the environment, rotate if needed |
| 403 | The recipient opted out; the error names the date and the words they used | Do not retry; remove them from your list |
| 429 | Monthly or daily allowance reached, including the headroom | Wait for the window, or upgrade the plan |
Everything in this guide runs on the free plan. For the full endpoint list, including conversations, contacts and campaigns, see What Is an SMS API and How to Use One. If you would rather have an AI agent do the calling, the MCP server guide exposes the same operations as tools.
FAQ
How do I send an SMS from a Ruby application?
POST JSON with to and body to https://smsnet.net/api/v1/messages/send, with your SMSNET API key in the X-API-Key header. The response returns a message_id and your remaining quota, and the message is sent from the Android phone connected to your account. Use Net::HTTP with a typed client.
Do I need Twilio or a carrier account to send SMS from Ruby?
No. SMSNET uses an Android phone and SIM you already own as the sender, so there is no carrier account and no number rental; you text from your own number on your own plan. The free plan covers 300 messages a month and replies are never counted.
How do I know the SMS was delivered?
Either poll GET /api/v1/messages and read each message's status, or register a webhook and receive a message.status event when the message reaches sent, delivered or failed. Delivery confirmation comes from the recipient's handset via the carrier, so timing varies by network.
Can my Ruby application receive SMS replies?
Yes. Poll GET /api/v1/messages?direction=inbound with the next_cursor from the previous call, or register an HTTPS webhook and receive message.received events signed with HMAC-SHA256 over the timestamp and raw body.
How fast does the message arrive?
An ordinary message is paced and usually leaves within a minute or two, subject to civil hours where the recipient is. A message marked transactional: true is handed to the phone immediately and typically reaches the handset in about a second. New lines are limited to 100 messages a day until they have warmed up.
What phone number does the recipient see?
The number of the SIM in your connected Android phone. It is your own number, so replies come straight back to you and the conversation stays in one thread.
Related guides
This is a spoke of What Is an SMS API and How to Use One. Siblings: Send an SMS from Node.js, Send an SMS from Python, Send SMS From PHP, Send SMS From Java, Send SMS From C#, Send SMS From Go. The phone comes from Turn Your Android Phone into an SMS Gateway; the agent route is What Is an MCP Server for SMS?.
Send your first message today
Free plan, no card: 400 messages a month from your own number, with the API, webhooks and MCP included.
Get the app See pricing