简体   繁体   中英

i want to send sms to phone using java

Can anyone tell me how to send sms through Java Web Application. I saw various solution but I am not getting them.

Can anyone help me.I dont want it to be limited to GSM phones.

I have tried this code,but it is not working

public void test() throws Exception{
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.port", "587");
            props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.auth", "true");

    Authenticator auth = new SMTPAuthenticator();
    Session mailSession = Session.getDefaultInstance(props, auth);
    // uncomment for debugging infos to stdout
    // mailSession.setDebug(true);
    Transport transport = mailSession.getTransport();

    MimeMessage message = new MimeMessage(mailSession);
    message.setContent("this is test mail", "text/plain");
    message.setFrom(new InternetAddress("friendwithme18@gmail.com"));
    message.setSubject("hello");
    message.addRecipient(Message.RecipientType.TO,
         new InternetAddress("phoneno@sms.gmail.com"));

    transport.connect();
    transport.sendMessage(message,
        message.getRecipients(Message.RecipientType.TO));
    transport.close();
}

private class SMTPAuthenticator extends javax.mail.Authenticator {
    public PasswordAuthentication getPasswordAuthentication() {
       String username = SMTP_AUTH_USER;
       String password = SMTP_AUTH_PWD;
       return new PasswordAuthentication(username, password);
    }
}

This looks promising:

SMS library for the Java platform
This library allows you to send SMSes (GSM) from the Java platform. It gives you full control over the SMS including the UDH field so you can create and send EMS messages, WAP push messages and nokia smart messages (picture, ringtone etc). The API can send SMS by using a GSM phone connected to the serial port or via a SMS gateway (like Clickatell).

I think it's best to know what network you are using to send SMS. The network may actually have their own set of APIs but under certain conditions like here in my country, Philippines, there is a "Labs" affiliate of a mobile network. Of course, you will also have to subscribe to the said network.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM