Send an SMS
In this code snippet you will see how to send an SMS using the Messages API.
For a step-by-step guide to this topic, you can read our tutorial Sending SMS messages with the Messages API.
Delivery receipts
The webhook used for the delivery receipt will depend on the type of authentication used:
| Authentication type used | Webhook used for delivery receipt |
|---|---|
| Basic Auth | account-level webhook is used for delivery receipt. |
| JWT Auth | application-level webhook is used for delivery receipt / status. |
Reception of delivery receipts depends on availability of network support.
Example
Find the description for all variables used in each code snippet below:
| Key | Description |
|---|---|
VONAGE_APPLICATION_ID | The Vonage Application ID. |
VONAGE_APPLICATION_PRIVATE_KEY_PATH | Private key path. |
VONAGE_PRIVATE_KEY_PATH | Private key path. |
VONAGE_FROM_NUMBER | Refer to |
VONAGE_BRAND_NAME | The alphanumeric string that represents the name or number of the organization sending the message. |
FROM_NUMBER | The phone number you are sending the message from. |
TO_NUMBER | The phone number you are sending the message to. |
NOTE: Don't use a leading + or 00 when entering a phone number, start with the country code, for example 447700900000.
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-sms.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
Create a class named SendSmsText and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.messages.sms with the package containing SendSmsText:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
Create a class named SendSmsText and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.messages.sms with the package containing SendSmsText:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-sms.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-sms.rb and add the following code:
Run your code
Save this file to your machine and run it:
Try it out
When you run the code a message is sent to the destination number.