views:

1269

answers:

8

I want to send SMS to a mobile phone from a web application, is it possible? How do I do it?

+7  A: 

the easiest way to do this is to use an SMS gateway.

there are lots out there, the one i've used is Clickatel to which i simply post an XML request and the gateway does the rest for next to nothing.

i have done this using java and apache commons HTTP Client

pstanton
+1  A: 

Here you can find a Java SMS API project in source forge.

Apart from that, you need a Sms Gateway for the infrastructure. Some companies provide you APIs that it is becoming as easy as pie to make the program.

Kubi
A: 

You can use this free Java sample program to send SMS from your PC using GSM modem connected to your computer to your COM port. You also need to download and install the Java comm api from Sun.

This program needs the following java files to function.

  1. SerialConnection.java (This file is used to connect to your COM port from your java program)

  2. SerialConnectionException.java (This file is for handling serial connection exceptions in your Java program)

  3. SerialParameters.java (This program is used to set your COM port properties for connecting to your com port from your java program)

  4. Sender.java (This is the program that implements runnable and sends SMS using the serial connection)

  5. SMSClient.java (This java class is the main class that can be instantiated in your own java program and called to send SMS. This program in turn will use all the above four files internally to send out your SMS).

Download Send SMS Java sample program files

/*
 *
 * A free Java sample program 
 * A list of java programs to send SMS using your COM serial connection
 * and a GSM modem
 *
 * @author William Alexander
 * free for use as long as this comment is included 
 * in the program as it is
 * 
 * More Free Java programs available for download 
 * at http://www.java-samples.com
 *
 *
 * Note: to use this program you need to download all the 5 java files
 * mentioned on top
 *
 */
public class SMSClient implements Runnable{

  public final static int SYNCHRONOUS=0;
  public final static int ASYNCHRONOUS=1;
  private Thread myThread=null;

  private int mode=-1;
  private String recipient=null;
  private String message=null;

  public int status=-1;
  public long messageNo=-1;


  public SMSClient(int mode) {
      this.mode=mode;
    }

  public int sendMessage (String recipient, String message){
    this.recipient=recipient;
    this.message=message;
    //System.out.println("recipient: " + recipient + " message: " + message);
    myThread = new Thread(this);
    myThread.start();
//    run();
    return status;
    }
    public void run(){

    Sender aSender = new Sender(recipient,message);

    try{
      //send message
          aSender.send ();

         // System.out.println("sending ... ");

      //in SYNCHRONOUS mode wait for return : 0 for OK,
      //-2 for timeout, -1 for other errors
      if (mode==SYNCHRONOUS) {
          while (aSender.status == -1){
            myThread.sleep (1000);
          }
      }
      if (aSender.status == 0) messageNo=aSender.messageNo ;

    }catch (Exception e){

        e.printStackTrace();

    }

    this.status=aSender.status ;

    aSender=null;


  }
}
ratty
Thanks ratty,i build this in net beans, may i know how to send sms can u tel me the steps involved
Aravindkumar
copying something from google doesn't really seem a good answer to me.
Valentin Rocher
concentrate on solutions dont bother about source mr.valentin
ratty
Using gsm modem attached to a pc for sending sms is slow. There is a certain limit on how many messages gsm modem can sen per second. Therefore it is better to use sms gateway provided by carrier.
Babar
A: 

Step-1. Download Mail.jar and Activation.jar (see Resources for links) and save to the Java library directory on your computer's local drive.

Step-2.

Start a new Java class in your Java Integrated Development Environment (IDE) and name it "MyMobileJava.java".

Step-3.

Enter the following Java libraries at the start of your Java class. These libraries include the required Java Mail and Communications API resources and other supporting Input/Output and Internet class libraries for sending SMS text messages.

import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

Step-4 Place the following Java code after the library import statements in order to instantiate the Java class and assign values for the default SMS text messages.

public class SMTPSend {

        public SMTPSend() {
        }

        public void msgsend() {
          String username = "MySMSUsername";
          String password = "MyPassword";
          String smtphost = "MySMSHost.com";
          String compression = "My SMS Compression Information";
          String from = "[email protected]";
          String to = "[email protected]";
          String body = "Hello SMS World!";
          Transport myTransport = null;

Step-5 Create Java code to create a new communications session that will then be used to configure the information contained within a text message. This information will then be prepared to be sent. Enter the following Java code in your Java class at the end of the code entered in step four.

 try {
    Properties props = System.getProperties();
    props.put("mail.smtp.auth", "true");
    Session mailSession = Session.getDefaultInstance(props, null);
    Message msg = new MimeMessage(mailSession);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(compression);
    msg.setText(body);
    msg.setSentDate(new Date());

Step-6 Send the text message by connecting to your SMS host address, saving changes to the message, and then sending the information. To do this, enter the following Java code to finish the Java class.

     myTransport = mailSession.getTransport("smtp");
      myTransport.connect(smtphost, username, password);
      msg.saveChanges();
      myTransport.sendMessage(msg, msg.getAllRecipients());
      myTransport.close();
     } catch (Exception e) {
        e.printStackTrace();
      }
   }

   public static void main(String[] argv) {
     SMTPSend smtpSend = new SMTPSend();
     smtpSend.msgsend();
   }
 } //enter code here`
ratty
Probably should add four spaces before each line of your code; then it's highlighted and not all mushed on one line.
icktoofay
Also selecting your code and pressing ctrl+K does that too.
icktoofay
thank you icktoofay
ratty
A: 

The easiest way to do this is to find an operator which supports sms's through mail..

Ex. You have Telia/Comviq/Chello or whatnot. If you send an email to; [email protected] it will send your email via sms to your phone.

A: 

Please have a look at SMSLib (http://smslib.org), an open source library for sending and receiving sms using a GMS modem or a mobile phone. It is really a great library.

Elias Haileselassie
A: 

I wrote a small maven lib for accessing the free (for customers only) web interface of the Swiss moblie operators Sunrise and Orange. You find the source on http://github.com/resmo/libjsms

resmo
A: 

Just retrieve all the cell phone Email-to-SMS (SMS Gateway) addresses and send an email to that email-to-SMS address.

0A0D