How to send SMS in Java
Well, SMS is a text messaging service component of most telephone, Internet, and mobile device systems. In Java, we can programmatically send SMS in Java with the BulkSMS API. Simply create an account at https://www.bulksms.com/account/#!/registration. Once you’ve successfully created an account at bulksms.com then go to Java and paste this code.
import java.net.*; import java.io.*; public class SendSms { static public void main(String[] args) { try { // Construct data String data = ""; /* * Note the suggested encoding for certain parameters, notably * the username, password and especially the message. ISO-8859-1 * is essentially the character set that we use for message bodies, * with a few exceptions for e.g. Greek characters. For a full list, * see: http://developer.bulksms.com/eapi/sub... */ data += "username=" + URLEncoder.encode("myusername", "ISO-8859-1"); data += "&password=" + URLEncoder.encode("xxxxxx", "ISO-8859-1"); data += "&message=" + URLEncoder.encode("This is a test", "ISO-8859-1"); data += "&want_report=1"; data += "&msisdn=44123123123"; // Send data // Please see the FAQ regarding HTTPS (port 443) and HTTP (port 80/5567) URL url = new URL("https://bulksms.vsms.net/eapi/submiss..."); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { // Print the response output... System.out.println(line); } wr.close(); rd.close(); } catch (Exception e) { e.printStackTrace(); } } }
Run it and enjoy it!