title: Java Code to send SMS from my Web Application to any Mobile in India
body: <p>I have a requirement where I need to send SMS from my Web Application to any Mobile in India .</p>
  
  <p>I got below code from a <a href="http://www.ipipi.com/help/send_text_message_using_java.htm" rel="nofollow">ipipi.com website</a>:</p>
  
  <p>I want to implement this functionality, could anybody please help me what values are to be provided here:</p>
  
  <pre><code>String username = "YoureIPIPIUsername";
  String password = "YourPassword";
  String smtphost = "ipipi.com";
  String compression = "Compression Option goes here - find out more";
  String from = "YoureIPIPIUsername@ipipi.com";
  String to = "DestinationPhoneNumber@sms.ipipi.com";
  String body = "Your Message";
  </code></pre>
  
  <p>SMTPSend.class</p>
  
  <pre><code>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 SMTPSend {
  
      public SMTPSend() {
      }
  
      public void msgsend() {
          String username = "YoureIPIPIUsername";
          String password = "YourPassword";
          String smtphost = "ipipi.com";
          String compression = "Compression Option goes here - find out more";
          String from = "YoureIPIPIUsername@ipipi.com";
          String to = "DestinationPhoneNumber@sms.ipipi.com";
          String body = "Your Message";
          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");
           tr.connect(smtphost, username, password);
           msg.saveChanges();
           tr.sendMessage(msg, msg.getAllRecipients());
           tr.close();
           } catch (Exception e) {
               e.printStackTrace();
           }
      }
  
        public static void main(String[] argv) {
            SMTPSend smtpSend = new SMTPSend();
            smtpSend.msgsend();
        }
  }
  </code></pre>