誰能告訴我如何通過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);
}
}
可能重複[如何使用Java發送短信](http://stackoverflow.com/questions/2234613/how-to-send-sms-using-java) – 2011-04-06 14:09:33
我看到了鏈接中的解決方案,但我是無法得到它 – coder 2011-04-06 16:41:30