Prerequisites
Before you begin, make sure you have:
- A SpringEdge account with an API key (sign up free at springedge.com) and your SMS service URL (
<SMS_SERVICE_URL>, shared after sign-up) - Java 11 or higher installed
- A DLT-registered sender ID and approved message template (for India)
Simple HTTP API
Form-encoded GET/POST request, JSON or XML responses
HTTPS + API Key
API key sent as a request parameter, with optional IP whitelisting
No External Dependencies
Works with the built-in java.net.http.HttpClient
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class SendSMS {
public static void main(String[] args)
throws Exception {
Map<String, String> params =
new LinkedHashMap<>();
params.put("apikey", "YOUR_API_KEY");
params.put("sender", "SEDEMO");
params.put("to", "9900XXXXXX");
params.put("message", "Your OTP is 482910");
params.put("format", "json");
String form = params.entrySet().stream()
.map(e -> e.getKey() + "=" + URLEncoder
.encode(e.getValue(),
StandardCharsets.UTF_8))
.collect(Collectors.joining("&"));
HttpRequest request = HttpRequest
.newBuilder(URI.create(
"<SMS_SERVICE_URL>/api/web/send/"))
.header("Content-Type",
"application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers
.ofString(form))
.build();
HttpResponse<String> response =
HttpClient.newHttpClient().send(request,
HttpResponse.BodyHandlers.ofString());
// JSON on success, e.g.
// {"groupID":61,"MessageIDs":"61-1",
// "status":"AWAITED-DLR"}
// plain text on error, e.g.
// "Invalid Mobile Numbers"
System.out.println(response.body());
}
}
STANDARD JAVA
Using Java HttpClient
This example uses Java 11's built-in HttpClient — no external libraries required. It sends a form-encoded POST to <SMS_SERVICE_URL>/api/web/send/ with your API key as the apikey parameter and each value URL-encoded.
With format=json the API returns the message ID (MessageIDs) and status AWAITED-DLR. Track delivery with a callbackurl delivery report or by polling the message status. Errors are plain-text messages such as Insufficient Credits.
Steps:
- Replace
YOUR_API_KEYwith your SpringEdge API key - Set
<SMS_SERVICE_URL>, the recipient number, sender ID, and message (must match a DLT-approved template) - Compile and run:
javac SendSMS.java && java SendSMS - Check the response for the
MessageIDsvalue
WITH OKHTTP
Using OkHttp Library
For production applications, OkHttp provides connection pooling, automatic retries, and cleaner syntax. Add the dependency to your Maven or Gradle project; FormBody builds the URL-encoded request for you.
Maven Dependency:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
import okhttp3.*;
public class SendSMSOkHttp {
public static void main(String[] args)
throws Exception {
OkHttpClient client = new OkHttpClient();
// FormBody URL-encodes each value
RequestBody body = new FormBody.Builder()
.add("apikey", "YOUR_API_KEY")
.add("sender", "SEDEMO")
.add("to", "9900XXXXXX")
.add("message", "Your OTP is 482910")
.add("format", "json")
.build();
Request request = new Request.Builder()
.url("<SMS_SERVICE_URL>"
+ "/api/web/send/")
.post(body)
.build();
try (Response response =
client.newCall(request).execute()) {
System.out.println(
response.body().string()
);
}
}
}
What You Can Build
OTP Verification
Add phone number verification to your Java web application's signup and login flows with one-time passwords.
Order Notifications
Send automated order confirmations, shipping updates, and delivery alerts from your Spring Boot or Java EE backend.
Bulk Campaigns
Send promotional SMS to thousands of recipients using Java's multithreading capabilities for parallel API calls.
CRM Integration
Connect your Java-based CRM or ERP system to send automated SMS alerts triggered by business events.
