• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Sending SMS from Java

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 = "[email protected]";
String to = "[email protected]";
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I access Gmail with JavaMail?
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What classes to import and what jar files to include?

Thanks,

Maki Jav
 
jagannadha reddy
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic