This discussion is archived
2 Replies Latest reply: Apr 3, 2013 12:15 PM by 1000888 RSS

Sending SMS using Java

User_Sep Newbie
Currently Being Moderated
Hi, My need is to send sms using java code. Also am going to use GSM modem. I googled a lot, but never helped to achieve. So pls guide me.

Thanks,
raka
  • 1. Re: Sending SMS using Java
    Kayaman Guru
    Currently Being Moderated
    Arunkumar Kootharasan wrote:
    I googled a lot, but never helped to achieve. So pls guide me.
    If Googling didn't help you, this forum will be useless.
  • 2. Re: Sending SMS using Java
    1000888 Newbie
    Currently Being Moderated
    See to send sms from your website you can do in two ways.
    1.First is create your own sms server.
    2.Purchage sms service from sms provider and the integrate it with your application
    Here is code:-


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */


    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.URLEncoder;
    import java.util.ArrayList;
    import java.util.Iterator;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**
    *
    * @author OM
    */
    public class sendsms extends HttpServlet {
         String username="apnarozgaar";
    String password="apnarozgaar1";
    String sender="ARozgaar";
    //String[] to={"9986847817","9036559762"};
    String[] to;
    String message="";
    String mtype = "N";
    String DR = "Y";
    String postData="";
    String to1;
    ArrayList al=new ArrayList();

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    to1=request.getParameter("to");
    String Phone;

    //File fl=new File();
    BufferedReader br=new BufferedReader(new FileReader("D://NEscript.txt"));
    while((Phone=br.readLine()) != null)
    {
         al.add(Phone);
         
    }
    Iterator itr1 = al.iterator();
              to = (String[]) al.toArray(new String[al.size()]);
                   
    try {

              //to="9036559762";
    // message=request.getParameter("dont wrry dear mujhe thodi tension hai").trim();
    for(int i=0;i<to.length;i++)
    {
         System.out.println("sender List:"+to);

    //to="9036559762";
    message="Hi It is a testing mas from RAM TEAM";
    postData += "username=" + URLEncoder.encode(username,"UTF-8") + "&password=" + password + "&sender=" + sender + "&to=" + to[i] + "&message=" + URLEncoder.encode(message,"UTF-8") + "&mtype=" + mtype + "&DR=" + DR;

    }
    Sms1 s=new Sms1();
    String result=s.sendSms(postData);

    if(result!=""){
         out.print(result);
         out.print("Message send successfully");
    }
    else
    out.print("error");

    } finally {
    out.close();
    }
    }



    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    }
    @Override
    public String getServletInfo() {
    return "Short description";
    }

    }

    Rinkoo Kushwah

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points