我想发送短信到手机使用java
问题描述:
谁能告诉我如何通过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);
}
}
答
这看起来很有希望:
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
答
我想最好知道你用什么网络发送短信。网络实际上可能有自己的一套API,但在菲律宾这样的特定条件下,有一家移动网络的“实验室”分支机构。当然,你也必须订阅上述网络。
可能重复[如何使用Java发送短信](http://*.com/questions/2234613/how-to-send-sms-using-java) – 2011-04-06 14:09:33
我看到了链接中的解决方案,但我是无法得到它 – coder 2011-04-06 16:41:30