SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending SMS from JAVA

    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 long post.
    Please help me to complete this, it is very urgent.

    Thanks&Regards
    Jagan.

  2. #2
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    According to this, there's a rather simple solution


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •