Sending SMS to your Mobile Through Java Program

Yes,we can send SMs Using our Java Program.These are the steps Note:Ipipi allows you to send only 5 sms free of cost,After that create one more account 1> create an account in http://www.ipipi.com/ 2>I created Account like this: username:  surajSMS password: suraj1233>Prepare the program in this way
SendSMS.java
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.*;

public class SendSMS {
    public SendSMS() {}
             //create an account on ipipi.com with the given username and password

    public void msgsend() { 
             String username = "surajSMS"; 
             //Your Credentials 
            String password = "suraj123"; 
            String smtphost = "ipipi.com";   
            //Ip/Name of Server 
            String compression = "None"; 
             //I dont want any compression 
            String from = "surajSMS@ipipi.com"; 
            //ur userid@ipipi.com 
            //This mobile number need not be registered with ipipi.com 
            String to = "919861098610@sms.ipipi.com";             //mobile number where u want to send sms
            String body = "Hi This Msg is sent through Java Code";

            Transport tr = null; 
            try { 
                Properties props = System.getProperties(); 
                props.put("mail.smtp.auth", "true"); 
                // Get a Session object 
                Session mailSession = 
                            Session.getDefaultInstance(props, null); 
                // construct the message 
                Message msg = new    
                             MimeMessage(mailSession);
                //Set message attributes
                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());
                tr = mailSession.getTransport("smtp"); 
                //try to connect 
                tr.connect(smtphost, username, password);
               msg.saveChanges();
               //send msg to all recipients 
               tr.sendMessage(msg, msg.getAllRecipients());      
               tr.close(); 
            } 
            catch (Exception e) { 
                e.printStackTrace();
            } 
    } 
    public static void main(String[] argv) { 
           SendSMS sms = new SendSMS(); 
           sms.msgsend(); 
           System.out.println("Successfull"); 
   } 
}

Download Source Here

11 thoughts on “Sending SMS to your Mobile Through Java Program

    • Hi trib,I think some mistake was done while adding jars,please download the source code given my me,i have also included jars there,open a new account,add those jars,modify the necessary details,and it will sure work fine.

      • using eclipse i got this msg…….

        javax.mail.MessagingException: Could not connect to SMTP host: ipipi.com, port: 25;
        nested exception is:
        java.net.ConnectException: Connection timed out: connectSuccessfull

        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
        at javax.mail.Service.connect(Service.java:275)
        at javax.mail.Service.connect(Service.java:156)
        at SendSMS.msgsend(SendSMS.java:51)
        at SendSMS.main(SendSMS.java:66)
        Caused by: java.net.ConnectException: Connection timed out: connect
        at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
        … 5 more

  1. thanx its working…….bt i cant send more than 5 sms for free
    i want to know hw to send via free sms sites like way2sms etc

  2. Hi,
    it is giving error
    503 5.7.1 Incorrect Authentication for Specified Email Address503 5.7.1 Incorrect Authentication for Specified Email Address

    Please help

  3. String to = “919861098610@sms.ipipi.com”;
    In the above code we have to place @sms.ipipi.com for the sending number or not..
    It was successful but the message is not going…
    Can anybody tell ?????

  4. This program is not working ya any one can help to solve this problem
    The error shows that

    C:\Documents and Settings\Administrator\Desktop\veeru\Javaprog>javac SendSMS.java

    C:\Documents and Settings\Administrator\Desktop\veeru\Javaprog>java SendSMS
    javax.mail.MessagingException: Could not connect to SMTP host: ipipi.com, port: 25, response: 421
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:996)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:197)
    at javax.mail.Service.connect(Service.java:233)
    at javax.mail.Service.connect(Service.java:134)
    at SendSMS.msgsend(SendSMS.java:47)
    at SendSMS.main(SendSMS.java:59)
    Successfull

  5. Hi…..
    I am getting this error…

    javax.mail.MessagingException: Could not connect to SMTP host: ipipi.com, port: 25;
    nested exception is:
    java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at com.javamail.sms.SendSMS.msgsend(SendSMS.java:52)
    at com.javamail.sms.SendSMS.main(SendSMS.java:64)
    Caused by: java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    … 5 more
    Successfull

Leave a Reply