3 Ways To Send Text Messages (SMS) with Ruby [How-to Guide]

Send SMS in Ruby with Twilio, Plivo, or Courier. Copy-paste code for each, plus how to route SMS, email, and push through one API.

Updated Jul 6, 2026

To send SMS in Ruby, call an SMS provider API from your Ruby app, pass the recipient phone number and message body, and handle delivery errors outside the user-facing request. You can call Twilio or Plivo directly, or use Courier as the notification layer above those providers so your app keeps one API for SMS, email, push, in-app, and Slack.

SMS is useful for time-sensitive product messages such as account verification, alerts, delivery updates, appointment reminders, and security notifications. The implementation choice depends on whether you only need one SMS provider or need routing, templates, preferences, logs, and multiple channels managed in one place.

Quick Ruby SMS path

For a small app, a direct provider SDK is usually enough: configure credentials, create a message, send it from a background job, and log the provider response. For a production notification system, keep the send logic behind a service object so you can change providers, add retries, or route through Courier without rewriting controllers.

Use Courier when SMS is part of a broader notification experience. Courier can route an SMS through Twilio, keep templates out of application code, show delivery logs, and let the same event trigger email, push, in-app, or Slack when needed.

1. Using Twilio API

Twilio API is one of the best services for sending SMS using Ruby. It provides a programmable SMS API with multiple additional features to make it a whole in one package. For example, you can use Twilio SMS API to send and receive SMS, monitor delivery statuses of messages, schedule deliveries, and more.

Advantages of using Twilio API

  • A most reliable way to send messages.
  • Good documentation and customer support.
  • Support multiple programming languages.

Disadvantages of Using Twilio API

  • More expensive than competitors.
  • Not very mobile-friendly.
  • Not easy for non-developer users to get started.

Tutorial: How to Send SMS Using a Twilio API

Step 1: Create a Twilio account and get a phone number

As the first step, you need to create a Twilio account. You can easily create a free Twilio account by following the steps in this guide.

Step 2: Add the Twilio gem to your project.

Install Twilio-Ruby gem to your project using gem install twilio-ruby -v 5.73.0 command.

Step 3: Update your code

Then, create a new file named sms_send.rb and update it with the below code.

require 'twilio-ruby'
module SMS
@account_sid = ENV['TWILIO_ACCOUNT_SID']
@auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(@account_sid, @auth_token)
def send_sms(from_phone_number, to_phone_number, message)
@client.messages.create(
from: from_phone_number,
to: to_phone_number,
body: message
)
end
end

Finally, call the send_sms method by passing the required input parameters like below:

@from = '+123456789'
@to= '+123456789'
@message= 'This is my first SMS'
send_sms(@from, @to, @message)

2. Using Plivo API

Plivo is another popular service for sending SMS using Ruby. It offers SDKs and RESTful APIs to implement SMS, audio messages, video messages, push notifications, and many other communication methods. In addition, Plivo API supports web, mobile and IoT applications.

Advantages of Using Plivo API

  • Affordable pricing.
  • Good customer and tech support.
  • Combination of long messages.
  • Support two-factor authentication.
  • APIs are customizable.

Disadvantages of Using Plivo API

  • No API channels are available for WhatsApp, social media, or online chat.
  • Does not support chatbots or multi-channel customer care.
  • Lack of proper error messages.

Tutorial: How to Send SMS Using a Plivo API

Step 1: Create a Plivo account and get a phone number

To begin, you will need a Plivo account and a phone number that can receive SMS messages. You can easily create a Plivo account by following the steps in this guide.

Step 2: Add the Twilio gem to your project

Install plivo-ruby gem to your project using gem install plivo command.

Step 3: Update your code

Then, create a new file named sms_send.rb and update it with the below code.

require 'rubygems'
require 'plivo'
include Plivo
module SMS
@client = RestClient.new("<auth_id>", "<auth_token>")
def send_sms(from_phone_number, to_phone_number, message)
message_created = client.messages.create(
from_phone_number,
[to_phone_number],
message
)
end
end

Finally, call the send_sms method by passing the required input parameters like below:

@from = '+123456789'
@to= '+123456789'
@message= 'This is my first SMS'
send_sms(@from, @to, @message)

3. Using Multi-Channel Notification API

In addition to the above APIs, you can use a multi-channel notification service like Courier to send SMS. Multi-channel notification services help you reach customers on multiple channels using a uniform API. Courier's mobile notification channel adds SMS, push, and in-app delivery without switching providers.

With the modern application requirements, using a multi-channel notification service like Courier can streamline your notification flow by creating all the relevant channels with them a single API.

Advantages of Using Multi-Channel Notification API

  • You can add additional notification channels without updating the code.
  • Smaller code base since you do not need to write code for each channel.
  • You can alert users via many notification channels using a single API.
  • Even non-technical users can manage your notification service.

Disadvantages of Using Multi-Channel Notification API

  • Limitations on the number of notifications you can get each month.
  • It can be expensive to consume numerous notification channels.

Tutorial: How to Send SMS Using a Multi-Channel Notification API

I will use Courier for this demonstration since it supports well-known SMS providers like Twilio, Plivo, MessageBird, and more.

Step 1: Creating a Courier account

You can easily create a free Courier account using this link - https://app.courier.com/signup.

Step 2: Creating a New Channel

Afterwards, create a new channel by selecting the Channels tab from the Courier dashboard. Next, you will see a list of SMS providers, and you can choose one from the list. Then enter the credentials for your chosen provider, such as an Originating Number and an Access Key, and click the Install Provider button.

Step 3: Creating a Notification

Select the Designer tab from the Courier dashboard and click the Create Notification button to create a new notification. There, select SMS as the channel and your provider as the delivery service. Afterwards, click the Publish Changes button, move to the Preview tab, and click the Create Test Event button to create a new event.

Step 4: Install Courier SDK

Install trycourier gem to your project using gem install trycourier command.

Step 5: Update your code

Then, create a new file named sms_send.rb and update it with the below code. Set your Courier API key as an environment variable so it stays out of source control, then send an SMS to a recipient by phone number.

require "courier"
client = Courier::Client.new(api_key: ENV["COURIER_API_KEY"])
begin
res = client.send_.message(
message: {
to: {
phone_number: "+15555550123"
},
content: {
title: "Order update",
body: "Hi Nomen, your order has shipped."
},
data: {
order_id: "1234"
}
}
)
puts res.request_id
rescue Courier::CourierAPIError => err
puts err.message
end

Courier returns a request_id you can use to look up delivery status in the logs. To route the SMS through a specific provider or send the same message across multiple channels, define the routing and content in a Courier notification template and reference it by template instead of inline content.

Frequently asked questions

How do I send an SMS in Ruby?

Install a provider gem, configure your credentials, and call the provider's send method with a recipient phone number and message body. With Twilio use Twilio::REST::Client and messages.create, with Plivo use RestClient and messages.create, and with Courier install the trycourier gem, create a Courier::Client.new(api_key:), and call client.send_.message.

Which SMS gem should I use in Ruby?

Use a direct provider gem such as twilio-ruby or plivo when you only need one SMS provider. Use the trycourier gem when SMS is part of a broader notification system, since Courier gives you one API for SMS, email, push, in-app, and Slack, plus routing, templates, and delivery logs.

How do I keep my SMS API keys out of source control?

Store credentials in environment variables and read them at runtime, for example ENV["COURIER_API_KEY"] or ENV["TWILIO_AUTH_TOKEN"]. Never commit keys to your repository, and use a secrets manager or your host's environment settings in production.

Should I send SMS from the request cycle or a background job?

Send SMS from a background job (for example Sidekiq or Active Job) rather than inside the web request. Provider calls add latency and can fail, so moving them out of the request keeps your app responsive and lets you retry failed sends without blocking the user.

How do I switch SMS providers without rewriting my Ruby code?

Route through Courier and configure the provider in the Courier dashboard rather than in code. Your app keeps calling client.send_.message, and you can change or add providers, add fallback routing, and update message content from the dashboard without a code deploy.

How do I send SMS to multiple channels from one Ruby call?

Use Courier and define the channels in a notification template, then send the event once with client.send_.message. The same call can trigger SMS, email, push, in-app, and Slack based on the template and each recipient's preferences, so you write the send logic once.

Conclusion

In this article, I have discussed three different ways to send SMS using Ruby. In addition, I have discussed the advantages and disadvantages of Twilio API, Plivo API, and multi-channel notification services. My suggestions will help you to select the best method to send SMS using Ruby based on your requirements.

FAQ

Frequently asked questions

Use a provider SDK or HTTP API, authenticate with provider credentials, pass a recipient number and message body, then send the request from your Ruby app.

One API, every channel

Ship notifications without the boilerplate

Courier gives you one API for email, SMS, push, and chat, with templates, routing, retries, and delivery logs built in.

Last updated Jul 6, 2026. Code samples are illustrative; provider APIs and pricing change over time, so check each provider’s docs before relying on them.