Prerequisites
Before you begin, make sure you have:
- A SpringEdge account with an API key (sign up free at springedge.com)
- Java 8 or higher installed
- A DLT-registered sender ID and approved message template (for India)
Sub-5ms API Response
Fast REST endpoint with JSON responses
HTTPS + Bearer Auth
Secure authentication with API key
No External Dependencies
Works with standard Java HttpURLConnection
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.*;
public class SendSMS {
public static void main(String[] args)
throws Exception {
String apiKey = "YOUR_API_KEY";
String json = "{"
+ "\"to\":\"+919876543210\","
+ "\"sender_id\":\"SPREDG\","
+ "\"message\":\"Your OTP is 482910\","
+ "\"type\":\"transactional\""
+ "}";
URL url = new URL(
"https://api.springedge.com/v1/sms/send"
);
HttpURLConnection conn =
(HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"application/json");
conn.setRequestProperty("Authorization",
"Bearer " + apiKey);
conn.setDoOutput(true);
try (OutputStream os =
conn.getOutputStream()) {
os.write(json.getBytes("utf-8"));
}
int code = conn.getResponseCode();
BufferedReader br = new BufferedReader(
new InputStreamReader(
conn.getInputStream(), "utf-8"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println("Status: " + code);
System.out.println("Response: " + sb);
}
}
STANDARD JAVA
Using HttpURLConnection
This example uses Java's built-in HttpURLConnection — no external libraries required. It sends a POST request to the SpringEdge SMS API with your API key and message payload.
The API returns a JSON response with the message ID and delivery status. You can use this message ID to track delivery via webhooks or polling.
Steps:
- Replace
YOUR_API_KEYwith your SpringEdge API key - Set the recipient number, sender ID, and message
- Compile and run:
javac SendSMS.java && java SendSMS - Check the response for the message ID
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 and start sending SMS with minimal code.
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();
String json = "{"
+ "\"to\":\"+919876543210\","
+ "\"sender_id\":\"SPREDG\","
+ "\"message\":\"Your OTP is 482910\","
+ "\"type\":\"transactional\""
+ "}";
RequestBody body = RequestBody.create(
json,
MediaType.parse("application/json")
);
Request request = new Request.Builder()
.url("https://api.springedge.com"
+ "/v1/sms/send")
.post(body)
.addHeader("Authorization",
"Bearer YOUR_API_KEY")
.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.
