File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending SMS from Java

 
jagannadha reddy
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I need to send SMS to client from my application. For this i followed sending SMS from email by using below 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 = "username";
String password = "password";
String smtphost = "smtp.gmail.com";
String compression = "My SMS Compression Information";
String from = "username@gmail.com";
String to = "mobilenumber@serviceprovider.com";
String body = "Hello SMS World!";
Transport myTransport = null;

try {
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", smtphost);
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.port","465");
//props.put("mail.smtp.starttls.required", "true");
Session mailSession = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailSession);
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());

myTransport = mailSession.getTransport("smtp");
myTransport.connect(smtphost, username, password);
msg.saveChanges();
myTransport.sendMessage(msg, msg.getAllRecipients());
myTransport.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] argv) {
SMTPSend smtpSend = new SMTPSend();
smtpSend.msgsend();
}
}


It compiled successfully, but while running this code getting below exception:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. s29sm10871689wak.14

What to do to resolve this?
Sorry for the big post.
Please help me to complete this, it is very urgent.

Thanks&Regards
Jagan.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
 
Gopinath Karyadath
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Maki Jav
Ranch Hand
Posts: 445
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What classes to import and what jar files to include?

Thanks,

Maki Jav
 
jagannadha reddy
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tried with above code, it is going to exception block and printing message as follows:

javax.microedition.io.ConnectionNotFoundException: sms
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnec
tor.java:185)
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.
java:162)
at javax.microedition.io.Connector.open(Connector.java:83)
at Javaronch.Sms(Javaronch.java:12)
at Javaronch.main(Javaronch.java:36)
Unable to connect to Station because of network problem

Please tell me the solution to resolve this and make it work successfully.

Regards
Jagan.
 
Gopinath Karyadath
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic