如何使用way2sms帐户从我的jsp发送短信 [英] how to send SMS from my jsp using way2sms account

查看:80
本文介绍了如何使用way2sms帐户从我的jsp发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用way2sms帐户从我的jsp程序向任何手机号码发送短信..

解决方案

首先要检查Way2SMS是否暴露了任何用于发送SMS的Web服务.如果是这样,请获取有关Web服务的详细信息并使用它来发送SMS.其中许多人在印度经营:
http://en.wikipedia.org/wiki/List_of_SMS_gateways [ http://bit.ly/wXCqnB [ ^ ].

抱歉,此建议是否多余.正如我所说:以防万一. :-)

现在,Rayeev Jayaram的建议可以很好地实现Way2SMS作为Web服务提供的服务.但是,乍一看,我找不到它.在这种情况下,您可以使用类似于 Web抓取的技术来模拟人类客户的输入.请查看我过去的答案以获取更多详细信息:

从网页中获取特定数据 [如何从另一个站点获取数据 [ ^ ].

—SA


1 下载Mail.jar和Activation.jar. (请参阅参考资料.)将文件保存到Java目录.在Java集成开发环境(IDE)中启动一个新的Java类.
2
将其重命名为"MyMobileJava.java".在Java类的开头输入以下库:



导入java.io. *;

导入java.net.InetAddress;

导入java.util.Properties;

导入java.util.Date;

导入javax.mail.*;

导入javax.mail.internet.*;

导入javax.activation.*;



这些库允许您使用Java发送和接收SMS消息.
3
在语句后插入以下代码:



公共类SMTPSend {



公共SMTPSend(){

}



公共无效msgsend(){

字符串用户名="MySMSUsername";

字符串密码="MyPassword";

字符串smtphost ="MySMSHost.com";

字符串压缩=我的SMS压缩信息";

来自="mySMSUsername@MySMSHost.com"的字符串;

字符串= ="PhoneNumberToText@sms.MySMSHost.com";

字符串正文="Hello SMS World!";

Transport myTransport = null;



这使您可以启动Java类并为SMS消息分配值.
4
创建用于配置SMS消息中的信息的代码.您将使用该信息来发送消息.在先前代码的末尾输入代码.



尝试{

属性props = System.getProperties();

props.put("mail.smtp.auth","true");

会话mailSession = Session.getDefaultInstance(props,null);

消息msg =新的MimeMessage(mailSession);

msg.setFrom(new InternetAddress(from));

InternetAddress [] address = {new InternetAddress(to)};

msg.setRecipients(Message.RecipientTyp…address);

msg.setSubject(compression);

msg.setText(body);

msg.setSentDate(new Date());
5
将SMS消息连接到您的SMS主机地址.保存对消息的更改并发送信息.为此,请输入以下代码:



myTransport = mailSession.getTransport("smtp");

myTransport.connect(smtphost,用户名,密码);

msg.saveChanges();

myTransport.sendMessage(msg,msg.getAllRecipients());

myTransport.close();

} catch(Exception e){

e.printStackTrace();

}

}


how to send SMS to any mobile number from my jsp program by using way2sms account..

解决方案

First thing is to check with Way2SMS if they are exposing any Web Service for sending SMS. If so, get the details about the Web Service and consume it to send SMS.


Just in case you haven''t done it so far: check this list of SMS Gateways; many of them operate in India:
http://en.wikipedia.org/wiki/List_of_SMS_gateways[^].

I heard that some free-of-charge SMS Gate services are emerging, try to find some:
http://bit.ly/wXCqnB[^].

Sorry if this advice is redundant. As I say: just in case. :-)

Now, the advice by Rajeev Jayaram can be good it Way2SMS really provides as Web service. But, from a first glance, I could not find a sing of it. In this case, you can simulate the input by a human customer using the technique similar to Web scraping. Please see my past answer for further detail:

get specific data from web page[^],
How to get the data from another site[^].

—SA


1 Download Mail.jar and Activation.jar. (See Resources.) Save the files to your Java directory. Start a new Java class in your Java Integrated Development Environment (IDE).
2
Rename it "MyMobileJava.java." Enter the following libraries in the beginning of your Java class:



import java.io.*;

import java.net.InetAddress;

import java.util.Properties;

import java.util.Date;

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;



These libraries allow you to send and receive SMS messages in Java.
3
Insert the following code after the statements:



public class SMTPSend {



public SMTPSend() {

}



public void msgsend() {

String username = "MySMSUsername";

String password = "MyPassword";

String smtphost = "MySMSHost.com";

String compression = "My SMS Compression Information";

String from = "mySMSUsername@MySMSHost.com";

String to = "PhoneNumberToText@sms.MySMSHost.com";

String body = "Hello SMS World!";

Transport myTransport = null;



This lets you initiate Java class and assign values for the SMS messages.
4
Create a code that you will use to configure the information within a SMS message. You will use the information to send the message. Enter the code at the end of the previous codes.



try {

Properties props = System.getProperties();

props.put("mail.smtp.auth", "true");

Session mailSession = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(mailSession);

msg.setFrom(new InternetAddress(from));

InternetAddress[] address = {new InternetAddress(to)};

msg.setRecipients(Message.RecipientTyp… address);

msg.setSubject(compression);

msg.setText(body);

msg.setSentDate(new Date());
5
Connect the SMS message to your SMS host address. Save changes to the message and send the information. To do this, enter the following code:



myTransport = mailSession.getTransport("smtp");

myTransport.connect(smtphost, username, password);

msg.saveChanges();

myTransport.sendMessage(msg, msg.getAllRecipients());

myTransport.close();

} catch (Exception e) {

e.printStackTrace();

}

}


这篇关于如何使用way2sms帐户从我的jsp发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆