谁能告诉我如何通过Java Web应用程序发送短信。我看到了各种各样的解决方案,但我没有得到它们。
有人能帮我吗?我不希望它仅限于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("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);
}
}发布于 2011-04-06 22:12:12
这看起来很有希望:
这个库允许您从Java平台发送SMSes (GSM)。它使您能够完全控制SMS,包括UDH字段,以便您可以创建和发送EMS消息、WAP推送消息和诺基亚智能消息(图片、铃声等)。该应用程序接口可以通过使用连接到串行端口的GSM电话或通过短信网关(如Clickatell)发送短信。
发布于 2011-04-06 22:50:25
我认为最好知道你正在使用什么网络来发送短信。网络实际上可能有他们自己的API集,但在某些情况下,比如在我的国家菲律宾,有一个移动网络的"Labs“附属机构。当然,您还必须订阅上述网络。
https://stackoverflow.com/questions/5567681
复制相似问题