如何使用javamail发送短信 [英] how to send SMS using javamail

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

问题描述

我尝试使用下面的代码通过使用way2sms帐户从jsp页面发送SMS..但是此代码未将SMS发送到指定的手机号码..如何解决此问题..

I tried the following code to send SMS from my jsp page by using way2sms account..but this code didnt send SMS to specified mobile number..how to solve this problem..

String username = "my mobile number";
String password = "my way2sms password";
String smtphost = "site3.way2sms.com";

String from = "my mobile number@site3.way2sms.com";
String to = "receiver mobile number@site3.way2sms.com";
String body = "Hello SMS World!";
Transport myTransport = null;
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.RecipientType.TO, address);

msg.setText(body);
msg.setSentDate(new Date());

myTransport = mailSession.getTransport("smtp");
myTransport.connect(smtphost, username, password);
msg.saveChanges();
myTransport.sendMessage(msg, msg.getAllRecipients());
myTransport.close();
out.print("sent");
} catch (Exception e) {
e.printStackTrace();
}

推荐答案

,您应该首先尝试将电子邮件发送到常规电子邮件帐户.这样行吗?

您可以使用本地电子邮件服务器进行测试.基于Web的服务通常仅允许有限数量的访问.将hmailserver检查为本地服务器.
you should first try to send an email to a regular email account. Does that work?

You can use a local emailserver for testing. Web based services often only allow a limited number of accesses. Check hmailserver as a local server.


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

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