Click here to Skip to main content
16,016,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to send SMS to any mobile number from my jsp program by using way2sms account..
Posted

First thing is to check with Way2SMS if they are exposing any Web Service for sending SMS. If so, get the details about the Web Service and consume it to send SMS.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Feb-12 15:11pm    
This is generally a good idea, but I could not see the signs of such having Web service, voted 4.

In case such server cannot be used, I explained alternative approach, please see.
--SA
Just in case you haven't done it so far: check this list of SMS Gateways; many of them operate in India:
http://en.wikipedia.org/wiki/List_of_SMS_gateways[^].

I heard that some free-of-charge SMS Gate services are emerging, try to find some:
http://bit.ly/wXCqnB[^].

Sorry if this advice is redundant. As I say: just in case. :-)

Now, the advice by Rajeev Jayaram can be good it Way2SMS really provides as Web service. But, from a first glance, I could not find a sing of it. In this case, you can simulate the input by a human customer using the technique similar to Web scraping. Please see my past answer for further detail:

get specific data from web page[^],
How to get the data from another site[^].

—SA
 
Share this answer
 
v2
1 Download Mail.jar and Activation.jar. (See Resources.) Save the files to your Java directory. Start a new Java class in your Java Integrated Development Environment (IDE).
2
Rename it "MyMobileJava.java." Enter the following libraries in the beginning of your Java class:



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.*;



These libraries allow you to send and receive SMS messages in Java.
3
Insert the following code after the statements:



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 = "mySMSUsername@MySMSHost.com";

String to = "PhoneNumberToText@sms.MySMSHost.com";

String body = "Hello SMS World!";

Transport myTransport = null;



This lets you initiate Java class and assign values for the SMS messages.
4
Create a code that you will use to configure the information within a SMS message. You will use the information to send the message. Enter the code at the end of the previous codes.



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.RecipientTyp… address);

msg.setSubject(compression);

msg.setText(body);

msg.setSentDate(new Date());
5
Connect the SMS message to your SMS host address. Save changes to the message and send the information. To do this, enter the following code:



myTransport = mailSession.getTransport("smtp");

myTransport.connect(smtphost, username, password);

msg.saveChanges();

myTransport.sendMessage(msg, msg.getAllRecipients());

myTransport.close();

} catch (Exception e) {

e.printStackTrace();

}

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900