Over five billion people send text messages a year: so chances are you are familiar with texting. However, you may not be familiar with the technology behind a text message. In this tutorial, you will learn about technologies like SMS that power text messages. Then, you will learn how to send a text message programmatically.
What is a text message?
A text message is an electronic message. Initially, a text message referred to SMS, which stands for short message service. SMS is a service for sending short messages over wireless networks using standardized communication protocols. Neil Papworth sent the first SMS message on December 3, 1992, when he wrote Merry Christmas to his co-worker Richard Jarvis.
Since then, texting has evolved. For example, people now often share images, audio, and other types of multimedia. This change led to the development of MMS, which stands for multimedia messaging service. As you may have guessed, MMS lets you send text messages with different types of multimedia, such as images.
Despite the advent of MMS, SMS messages remain popular, with over two trillion sent every year.
One advantage of SMS messages is they are cheaper to send. Another advantage is not all customers can receive MMS messages.
Now that you are familiar with the technologies behind text messages let's dive into sending one with just a few lines of code.
To follow this tutorial, you need to create a Vonage account.
How to send a text message
Sending a text message programmatically is simple.
You can write code to use Vonage's SMS API to send a text message in less than five minutes.
Ready to give it a try?
First, open up your command line and set the following environment variables:
export VONAGE_BRAND_NAME export TO_NUMBER export VONAGE_API_KEY export VONAGE_API_SECRET
Next, create an sms.sh file like this:
curl -X "POST" "https://rest.nexmo.com/sms/json" \ -d "from=$VONAGE_BRAND_NAME" \ -d "text=A text message sent using the Vonage SMS API" \ -d "to=$TO_NUMBER" \ -d "api_key=$VONAGE_API_KEY" \ -d "api_secret=$VONAGE_API_SECRET"
Finally, type the following command to send an SMS message:
If you are testing this code by sending an SMS message to yourself, you should receive a text message shortly.
You can send a different message by replacing A text message sent using the Vonage SMS API in your code with a different message.
You now know how to send an SMS message programmatically!
If you have any questions about using the Vonage SMS API, you can reach out to our developer relations team on Slack or Twitter.
Thanks for reading!