2011-04-06 95 views
1

誰能告訴我如何通過Java Web應用程序發送短信。 我看到了各種解決方案,但我沒有得到它們。我想發送短信到手機使用java

任何人都可以幫助我,我不希望它僅限於GSM手機。

我曾嘗試這個代碼,但它不工作

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("[email protected]")); 
    message.setSubject("hello"); 
    message.addRecipient(Message.RecipientType.TO, 
     new InternetAddress("[email protected]")); 

    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); 
    } 
} 
+2

可能重複[如何使用Java發送短信](http://stackoverflow.com/questions/2234613/how-to-send-sms-using-java) – 2011-04-06 14:09:33

+0

我看到了鏈接中的解決方案,但我是無法得到它 – coder 2011-04-06 16:41:30

回答

0

這看起來很有希望:

SMS library for the Java platform
該庫允許您從發送的短信 (GSM) Java平臺。它給你 你完全控制的SMS 包括UDH領域,所以你可以 創建和發送EMS消息,WAP推 消息和諾基亞智能消息 (圖片,鈴聲等)。 API可以通過使用連接到串行端口的GSM電話 或通過 SMS網關(如Clickatell)發送SMS。

+0

www.clickatell.com本網站不開放。我不希望它在GSM調制解調器 – coder 2011-04-06 14:18:39

0

我想最好知道你用什麼網絡發送短信。網絡實際上可能有自己的一套API,但在菲律賓這樣的特定條件下,有一家移動網絡的「實驗室」分支機構。當然,你也必須訂閱上述網絡。