Now lets discuss on this topic::
That is how do i send sms through a java program...
For this u need the following::
1.)Connect ur phone to ur computer using bluetooth and check out the port number to which it is connected through the phone and modem options in the control panel.
2.) Download comm.jar. It comes with the javaComm api , The official API for serial communication in Java.
Several things to do before running the code is::
1.) include the comm.jar file in your library.
2.) copy the win32com.dll file from the javacomm folder that u will download and paste it into the jre/bin folder of jdk.
3.) Copy the javax.comm.properties file and paste it into the jdk/lib folder.
Now in the following code the AT commands are used to send the commands to the mobile phone through the port number mentioned in the code, through which the mobile is connected to the computer..
the AT commands make the phone send an sms to the mobile number mentioned in the code..
The code is as follows::
import javax.comm.*;
import java.util.*;
import java.io.*;
public class Main {
public Main() {
}
public static void main(String[] args) {
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null; // will be set if port found
String wantedPortName = "COM5";
while (portIdentifiers.hasMoreElements())
{
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&
pid.getName().equals(wantedPortName))
{
portId = pid;
break;
}
}
if(portId == null)
{
System.err.println("Could not find serial port " + wantedPortName);
System.exit(1);
}
SerialPort port = null;
try {
port = (SerialPort) portId.open(
"name", // Name of the application asking for the port
10000 // Wait max. 10 sec. to acquire port
);
} catch(PortInUseException e) {
System.err.println("Port already in use: " + e);
System.exit(1);
}
try
{
port.setSerialPortParams(
115200,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
}
catch(Exception e)
{
System.out.println(e.toString());
}
BufferedReader is = null;
PrintStream os = null;
try {
is = new BufferedReader(new InputStreamReader(port.getInputStream()));
}
catch (IOException e) {
System.err.println("Can't open input stream");
is = null;
}
try{
os = new PrintStream(port.getOutputStream(), true);
}
catch (IOException e) {
System.err.println("Can't open output stream");
is = null;
}
os.print("AT");
os.print("\r\n");
try
{
System.out.println(is.readLine());
System.out.println(is.readLine());
System.out.println(is.readLine());
}
catch (IOException e) {
System.err.println("Can't recieve input signals");
}
os.print("AT+CMGF=1");
os.print("\r\n");
try
{
System.out.println(is.readLine());
System.out.println(is.readLine());
System.out.println(is.readLine());
}
catch (IOException e) {
System.err.println("Can't recieve input signals");
}
char qu=34;
char cz=26;
os.print("AT+CMGS="+qu+"+919894198941"+qu+"\r\n");
os.print("hello india"+cz+"\r");
try
{
System.out.println(is.readLine());
System.out.println(is.readLine());
System.out.println(is.readLine());
System.out.println(is.readLine());
System.out.println(is.readLine());
System.out.println(is.readLine());
System.out.println(is.readLine());
}
catch (IOException e) {
System.err.println("Can't recieve input signals");
}
port.close();
}
} //End Of class......
Thats it..........
Few of the interesting SQL features and practices that I have worked and some implementation issues faced
Tuesday, November 25, 2008
How do i Use Hyper Terminal in Vista...?????
Most of us might have used the hyper terminal service in windows xp and all..
But all of a sudden what we find is that the vista is missing the hyper terminal service..
The hyper Terminal is to be found no where in vista.....
So the best possible solution is as Follows:::
Copy the following file from the windows xp computer windows\system32 folder and paste it into yours::
1.) hypertrm.dll
2.) hypertrm.exe
or just download the given two files into ur vista comp..
Thats it...Its that Easyy..!!!
But all of a sudden what we find is that the vista is missing the hyper terminal service..
The hyper Terminal is to be found no where in vista.....
So the best possible solution is as Follows:::
Copy the following file from the windows xp computer windows\system32 folder and paste it into yours::
1.) hypertrm.dll
2.) hypertrm.exe
or just download the given two files into ur vista comp..
Thats it...Its that Easyy..!!!
Send E-mail through your JAVA Program............
Lets discuss about how to send an email through a java program.
U will need to download the following files to run this program as it will be using them:
1.) mail.jar ( from javamail download)
2.) activation.jar (from javabeans activation framework (JAF) download).
Download these files and include them in your project.
it might look like this::
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendEmail {
public static void main(String[] args) {
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to = "bbc@hotmail.com";
String from = "abc@yahoo.com";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "smtp.yourisp.net";
//or:: String host = "192.168.22.11";
// Create properties, get Session
Properties props = new Properties();
// If using static Transport.send(),
// need to specify which host to send it to
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getInstance(props);
try {
// Instantiate a message
Message msg = new MimeMessage(session);
//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Send E-mail through java");
msg.setSentDate(new Date());
// Set message content
msg.setText("Your loss has been registered successfully. Please save the LossID for future reference");
//Send the message
Transport.send(msg);
}
catch (MessagingException ex) {
// Prints all nested (chained) exceptions as well
ex.printStackTrace();
}
}
}//End of class
In this way the email gets queued into ur server to be sent.
Remember one thing.. see to it that the jdk u using is compatible with the mail.jar and activation.jar u going to use. For example u might not be able to use the latest mail.jar or activation.jar with the old jdk.
Thats it... Its that easy..
U will need to download the following files to run this program as it will be using them:
1.) mail.jar ( from javamail download)
2.) activation.jar (from javabeans activation framework (JAF) download).
Download these files and include them in your project.
it might look like this::
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendEmail {
public static void main(String[] args) {
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to = "bbc@hotmail.com";
String from = "abc@yahoo.com";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "smtp.yourisp.net";
//or:: String host = "192.168.22.11";
// Create properties, get Session
Properties props = new Properties();
// If using static Transport.send(),
// need to specify which host to send it to
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getInstance(props);
try {
// Instantiate a message
Message msg = new MimeMessage(session);
//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Send E-mail through java");
msg.setSentDate(new Date());
// Set message content
msg.setText("Your loss has been registered successfully. Please save the LossID for future reference");
//Send the message
Transport.send(msg);
}
catch (MessagingException ex) {
// Prints all nested (chained) exceptions as well
ex.printStackTrace();
}
}
}//End of class
In this way the email gets queued into ur server to be sent.
Remember one thing.. see to it that the jdk u using is compatible with the mail.jar and activation.jar u going to use. For example u might not be able to use the latest mail.jar or activation.jar with the old jdk.
Thats it... Its that easy..
Subscribe to:
Comments (Atom)