【问题标题】:i want to send sms to phone using java我想使用java向手机发送短信
【发布时间】:2011-04-06 14:07:10
【问题描述】:

谁能告诉我如何通过 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);
    }
}

【问题讨论】:

标签: java


【解决方案1】:

这看起来很有希望:

SMS library for the Java platform
该库允许您发送短信 (GSM) 来自 Java 平台。它给 你完全控制短信 包括 UDH 字段,以便您可以 创建和发送 EMS 消息,WAP 推送 消息和诺基亚智能消息 (图片,铃声等)。 API 可以 使用 GSM 手机发送短信 连接到串行端口或通过 SMS 网关(如 Clickatell)。

【讨论】:

  • www.clickatell.com 此站点未打开。我不希望它位于 GSM 调制解调器中
【解决方案2】:

我认为最好知道您使用什么网络发送短信。该网络实际上可能有自己的一组 API,但在某些条件下,例如在我的国家菲律宾,有一个移动网络的“实验室”附属机构。当然,您还必须订阅上述网络。

【讨论】:

    猜你喜欢
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多