This is an archived repository. If you have any questions, feel free to reach out to us at devrel@vonage.com or through our Community Slack at https://developer.vonage.com/community/slack.
This repository is part of the How to Send SMS Messages With Java tutorial.
- Java Development Kit (JDK)
- Gradle for building your project
- A Vonage Account and Virtual Number
We've built this example using JDK 16 and Gradle 7.1
Navigate to the project folder in your terminal and run:
gradle buildIn SendSMS.java, replace the placeholders with string values as follows:
| KEY | DESCRIPTION |
|---|---|
VONAGE_API_KEY |
Your API key, shown in your account overview. |
VONAGE_API_SECRET |
Your API secret, shown in your account overview. |
TO_NUMBER |
The number you are sending the SMS to in E.164 format. For example 447401234567. |
VONAGE_BRAND_NAME |
Sender ID, the number or text shown on a handset when it displays your message. |
Note: In some countries (US),
VONAGE_BRAND_NAMEhas to be one of your Vonage virtual numbers. In other countries (UK), you're free to pick an alphanumeric string value—for example, your brand name like AcmeInc. Read about country-specific SMS features on the dev portal.
Save and run gradle run.
You should see something like this printed to the screen:
Message sent successfully.[com.vonage.client.sms.SmsSubmissionResponseMessage@f0f0675[to=447401234567,id=13000001CA6CCC59,status=OK,remainingBalance=27.16903818,messagePrice=0.03330000,network=23420,errorText=<null>,clientRef=<null>]]
... and you should receive a text message! If it didn't work, check out if something was printed after ERR: in the line above, and maybe wait a few more seconds for the message to appear.