2

I need to write a program that should be able to send a text SMS to mobile phone through java programming. What i got to know so far is using SMS Gateways and connect modem with sim card.

But I cannot install SMS Gateways and modem on client machine. Can i use smtp host.

How can i use Web Service to send sms?

Your time and contribution will be highly appreciated.

sTg
  • 4,313
  • 16
  • 68
  • 115
Abdul
  • 1,130
  • 4
  • 29
  • 65

1 Answers1

5

Using the twilio SMS gateway, you can easily accomplish this.

import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.MessageFactory;
import com.twilio.sdk.resource.instance.Message;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "AC32a3c49700934481addd5ce1659f04d2";
  public static final String AUTH_TOKEN = "{{ auth_token }}";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the MessageList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Body", "Abdul please?! I show you"));
    params.add(new BasicNameValuePair("To", "+14159352345"));
    params.add(new BasicNameValuePair("From", "+14158141829"));

    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    System.out.println(message.getSid());
  }
}

Here is a link to the twilio library: https://www.twilio.com/docs/java/install

rickyrobinett
  • 1,224
  • 10
  • 13
Scott 'scm6079'
  • 1,517
  • 13
  • 25
  • Hi scott. Is this free? – Aditya Singh Jun 13 '15 at 07:24
  • The library is free and open source, but you will need a phone number to use it, which costs one dollar if you continue after their free trial. – Scott 'scm6079' Jun 13 '15 at 07:33
  • Thank you very much for your hlep. Actually I need a way that should not have any constraints like I should have phone number and I should pay one dollar. After installing my app on client machine he will not agree with these conditions. – Abdul Jun 15 '15 at 06:15
  • I can use smtp server..... Client can provide his smtp server details. – Abdul Jun 15 '15 at 06:15