Rate this page:

Send SMS and MMS Messages In Tcl/Tk

Today we'll use Tcl and the Tk graphical toolkit to rapidly prototype a Twilio-powered SMS and MMS sending application. We're going to be using the packages ttk (which will require Tcl 8.5+), tls, base64, and http.

Sign Up for (or Sign Into) a Twilio Account

You'll need to either have an existing Twilio account or create a new account to try out the Tcl code.

Don't have an account yet? Sign up for a free Twilio trial!

Purchase or Find a SMS-Capable Number

You'll need a SMS (or optionally, MMS) capable number to use this demo application. Purchase a new SMS-enabled number or use one that you already own.

From the Twilio Console, click the '#' hash tag to look at Phone Numbers. Any numbers you have purchased will have the capabilities listed in the middle. 'SMS' and 'MMS' enabled numbers will appear with an icon:

Checking a Twilio Phone Number for SMS Capability

If you need to purchase a number, navigate to the 'Buy a Number' link and click the SMS checkbox (and optionally the MMS checkbox). Hit 'Search' and you should see all of the numbers available.

Buy a SMS-Capable Twilio Phone Number

Prerequisites for This Tcl MMS and SMS Guide

Many POSIX-Compliant operating systems ship with a distribution of Tcl and a number of popular packages. tls, however, may not be installed on your machine - you can access the tls package's site here. Alternatively, ActiveState maintains a number of excellent distributions of Tcl which make it easy to install packages.

TCL packages needed:

  • tls
  • http
  • base64
  • Tk

We were able to run the demo with the default Tcl8.5 distribution that comes with recent versions of Mac OS X. Here's an example session in bash on Mac OSX 10.11.6:

git clone
cd twilio-tcl-demo
export TWILIO_AUTH_TOKEN=yourauthtokengoeshere
export TWILIO_PHONE_NUMBER=+18005551212
chmod 755 twilio.tcl
/usr/bin/tclsh8.5 /twilio.tcl # Or wherever; default 8.5 worked on our Mac

Send an SMS or MMS Message with TCL/Tk

Our sample application shows how to bring up a cross-platform GUI with Tcl and Tk, then quickly send out a text message.

The GUI code is pretty boilerplate, other than the fact we're taking full advantage of ttk widgets.

        Grab the 'to' number, message body, and optional image URL for Twilio to send an SMS or MMS

        Set up a Tcl/Tk GUI

        Grab the 'to' number, message body, and optional image URL for Twilio to send an SMS or MMS

        After submitting the form, we first run a function to get the current state of all the GUI elements. Your production application should perform more exhaustive checks than we're demonstrating, but for now we'll just let Twilio reject our out-of-scope requests (like letters instead of phone numbers!).

        Following that, we get to the heart of the SMS and MMS sending code. The send_sms{} procedure should be easily portable to your own application. It takes phone numbers, a message body, Twilio account credentials, and an optional media url as input and POSTS to Twilio's REST API.

              Use the tls and http packages to POST to Twilio

              Send an SMS or MMS

              Use the tls and http packages to POST to Twilio

              Whether Twilio sends out an MMS or an SMS depends on the content of the Media URL and the number's home country. Twilio currently supports MMS messages in the United States and Canada. Other countries will have the image appended to the body as an automatically shortened URL.

              Tickle Your Fancy with Twilio and... Tcl

              With the power of Twilio's REST APIs you can quickly integrate communications into your application, no matter the language. Whether that's embedding Twilio connectivity in your appliance, prototyping a desktop support application, SMSing the whole design team when the routes are too scenic or texting you when there's another Tcl flamewar on your favorite newsgroup... we've got your back.

              With Twilio's API and your application, the possibilities are endless.

              We can't wait to see what you build - let us know on Twitter when you've got something to show!

              Paul Kamp
              Rate this page:

              Need some help?

              We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.


                    Thank you for your feedback!

                    Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

                    Sending your feedback...
                    🎉 Thank you for your feedback!
                    Something went wrong. Please try again.

                    Thanks for your feedback!

                    Refer us and get $10 in 3 simple steps!

                    Step 1

                    Get link

                    Get a free personal referral link here

                    Step 2

                    Give $10

                    Your user signs up and upgrade using link

                    Step 3

                    Get $10

                    1,250 free SMSes
                    OR 1,000 free voice mins
                    OR 12,000 chats
                    OR more