In most of the forums i found this question.How to send SMS Using java.
For answering this question i spent few hours for you guys.
For sending SMS you need to have the following files
1) javax.comm.properties
2) comm.jar
3) win32com.dll
In this Link you can download the files.Let me know if the given link is broken.So that i will upload the files and change the link here.
Check the java_home twice before copy and paste the files.Because most of the problems occurred by pasting the files in wrong folder.
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib
%JAVA_HOME%/bin
%JAVA_HOME%/jre/bin
%windir%System32
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib/ext
Okay i believe you placed all files in respective folder correctly.
Wait guys i heard your mind voice,you are asking where is the java program.
How i will forget,here you go for java programs
Want to Send Mail Using java program then click this Link and for more java program click this Link.
Do post your comments.
For answering this question i spent few hours for you guys.
For sending SMS you need to have the following files
1) javax.comm.properties
2) comm.jar
3) win32com.dll
In this Link you can download the files.Let me know if the given link is broken.So that i will upload the files and change the link here.
Check the java_home twice before copy and paste the files.Because most of the problems occurred by pasting the files in wrong folder.
javax.comm.properties:
Should falls under%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib
win32com.dll:
Should falls under%JAVA_HOME%/bin
%JAVA_HOME%/jre/bin
%windir%System32
comm.jar:
Should falls under%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib/ext
Okay i believe you placed all files in respective folder correctly.
Wait guys i heard your mind voice,you are asking where is the java program.
How i will forget,here you go for java programs
import java.io.IOException; import java.util.Enumeration; import javax.comm.CommPortIdentifier; import javax.comm.PortInUseException; import javax.comm.SerialPort; import javax.comm.UnsupportedCommOperationException; public class SriramSMS { public void sendsms() { static Enumeration portList; static CommPortIdentifier portId; static SerialPort serialPort; static OutputStream outputStream; String messageString = ""; String userName=""; String phoneNumber=""; Thread thread; try { userName = "periodicUpdates.blogspot.com"; phoneNumber = "9876543210"; messageString = " Hi." +userName+"welcome to this blog" ; String line1 = "AT+CMGF=1\r\n"; String line2 = "AT+CMGS=" + phoneNumber + "\r\n"+messageString+ "\r\n"; String line3 = "\u001A"; // Here initialize the driver class String driverName = "com.sun.comm.Win32Driver"; CommDriver commdriver = (CommDriver)Class.forName(driverName).newInstance(); commdriver.initialize(); portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println("SMS Sending........" + portId.getName()); if((portId.getName().equals("COM1"))) { try { serialPort = (SerialPort) portId.open("SimpleWriteApp",10000); System.out.println("sms sending port--->"+serialPort); outputStream = serialPort.getOutputStream(); serialPort.setSerialPortParams(230400,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE); outputStream.write(line1.getBytes()); outputStream.write(line2.getBytes()); outputStream.write(line3.getBytes()); outputStream.flush(); thread.sleep(5000); serialPort.close(); } catch (PortInUseException portUse) { System.out.println("Port In Use " + portUse.toString()); } catch (UnsupportedCommOperationException unsuppComOperExcep) { System.out.println("UnsupportedCommOperationException occured:::"+unsuppComOperExcep.toString()); } catch (IOException ioExcep) { System.out.println("Error occured while writing to output stream IOException" + ioExcep.toString()); } catch(Exception excep) { System.out.println("Error writing message with exception while closing " +excep.toString()); } } } } } catch(Exception excep) { System.out.println("EXCEPTION raised while writing message@@" +excep.toString()); } } }You got the program for sending sms through java program.
Want to Send Mail Using java program then click this Link and for more java program click this Link.
Do post your comments.