Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Working with an SMS Gateway

After the PC is wired to a cellular network, you need to install an SMS gateway on your machine to mediate the transmission of SMS messages. An alternative is to be wired directly to a major telecom carrier's SMS gateway. Many companies provide SMS gateways, with accompanying Java libraries that you use to transmit SMS. Among them are Kannel, UniPro, and Simplewire, though you're sure to find others once you start looking around.

With your gateway up and running, creating an application that sends an SMS message is a simple affair. The code below shows you how to iterate through a list of phone numbers to send an SMS to each member of the list, using the UniPro product. It's a bare-bones example, but demonstrates the simplicity of sending an SMS message using a third-party SMS gateway product.

// Import SMLib classes
 import com.unipro.smlib.*;
 public class runSMS {
  public static void main(String[] s) {
 //Make a phoneList
 String[] phoneList = new String[4]
 phonelist[0] = "2125551212"
 phonelist[1] = "2135551212"
 phonelist[2] = "6175551212"
 phonelist[3] = "2015551212"

//Create an instance of the SmsManager class
   SmsManager smsManager = SmsManager.getInstance();
   try {
    // Initialize the UniPro library (UniPro-specific stuff)
    smsManager.init(new Configurator(Configurator.PORT_COM1,
   } catch (Exception e) {
    // Handle exceptions of initializations here
   try {
    // Go through the party list and send a party invitation
    // to each member on the list

    int i =0
    for(i=0;i < phoneList.length;i++){
        smsManager.sendMessage(new OutMessage(phoneList[i],
                 "Dude, come to my party"));
   } catch (Exception e) {
    // Handle the exceptions
   // Close up shop
  • + Share This
  • 🔖 Save To Your Account