This folder contains a Java application demonstrating how to send SMS messages using the EasySendSMS REST API.
examples/java/
├── pom.xml # Maven build file
├── README.md # This file
└── src/
└── main/
└── java/
└── com/
└── easysendsms/
└── example/
├── EasySendSmsClient.java # Dedicated API client class
└── SendSmsExample.java # Main class with 4 usage examples
A self-contained API client class that handles:
- HTTP requests via Java's built-in
java.net.http.HttpClient(Java 11+) - Authentication (
apikeyheader) - JSON payload construction (no external libraries needed)
- Proper JSON string escaping (including Unicode)
- Response output with color-coded console messages
The entry-point class that demonstrates four common use cases:
- Single Recipient (plain text)
- Multiple Recipients (bulk sending)
- Unicode Message (Arabic)
- Scheduled Message
- Java 11+ (JDK)
- Apache Maven 3.6+ (optional, for building with Maven)
- An active EasySendSMS account
- Your EasySendSMS API Key (found in Account Settings → REST API in the dashboard)
Note: This example uses Java's built-in
java.net.http.HttpClientand has zero external dependencies.
macOS / Linux:
export EASYSENDSMS_API_KEY="YOUR_API_KEY"Windows (Command Prompt):
set EASYSENDSMS_API_KEY=YOUR_API_KEYWindows (PowerShell):
$env:EASYSENDSMS_API_KEY="YOUR_API_KEY"cd examples/java
mvn clean compile exec:java -Dexec.mainClass="com.easysendsms.example.SendSmsExample"Or build a JAR and run it:
mvn clean package
java -jar target/java-send-sms-example-1.0.0.jarIf you do not have Maven installed, you can compile and run directly:
cd examples/java
# Compile
javac -d out src/main/java/com/easysendsms/example/*.java
# Run
java -cp out com.easysendsms.example.SendSmsExampleThe application runs four examples and prints formatted API responses to the console. Success messages appear in green, errors in red, and warnings in yellow.
--- Example 1: Single Recipient (Plain Text) ---
SMS Sent Successfully!
Response: {"status":"OK","scheduled":"Now","messageIds":["OK: 1a2b3c4d-..."]}
--- Example 2: Multiple Recipients (Bulk) ---
SMS Sent Successfully!
Response: {"status":"OK","scheduled":"Now","messageIds":["OK: ...","OK: ...","OK: ..."]}
--- Example 3: Unicode Message (Arabic) ---
SMS Sent Successfully!
Response: {"status":"OK","scheduled":"Now","messageIds":["OK: ..."]}
--- Example 4: Scheduled Message ---
SMS Sent Successfully!
Response: {"status":"OK","scheduled":"2026-03-15T10:00:00","messageIds":["OK: ..."]}
If there is an API error (e.g., insufficient credits), the output will look like this:
API Error (402)
Response: {"error":4015,"description":"Insufficient credits."}
| Detail | Value |
|---|---|
| Base URL | https://restapi.easysendsms.app/v1/rest/sms/send |
| Method | POST |
| Content-Type | application/json |
| Authentication | apikey header |
| Documentation | https://www.easysendsms.com/rest-api |