我有一个要求,我需要从我的 Web 应用程序向印度的任何移动设备发送 SMS。
我从 ipipi.com website 得到以下代码:
我想实现这个功能,谁能帮我在这里提供什么值:
String username = "YoureIPIPIUsername";
String password = "YourPassword";
String smtphost = "ipipi.com";
String compression = "Compression Option goes here - find out more";
String from = "YoureIPIPIUsername@ipipi.com";
String to = "DestinationPhoneNumber@sms.ipipi.com";
String body = "Your Message";
SMTPSend.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.*;
public class SMTPSend {
public SMTPSend() {
}
public void msgsend() {
String username = "YoureIPIPIUsername";
String password = "YourPassword";
String smtphost = "ipipi.com";
String compression = "Compression Option goes here - find out more";
String from = "YoureIPIPIUsername@ipipi.com";
String to = "DestinationPhoneNumber@sms.ipipi.com";
String body = "Your Message";
Transport tr = null;
try {
Properties props = System.getProperties();
props.put("mail.smtp.auth", "true");
// Get a Session object
Session mailSession = Session.getDefaultInstance(props, null);
// construct the message
Message msg = new MimeMessage(mailSession);
//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(compression);
msg.setText(body);
msg.setSentDate(new Date());
tr = mailSession.getTransport("smtp");
tr.connect(smtphost, username, password);
msg.saveChanges();
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] argv) {
SMTPSend smtpSend = new SMTPSend();
smtpSend.msgsend();
}
}
最佳答案
如果上面的代码链接到将传入的电子邮件消息转换为传出的 SMS 消息的服务,您可能需要购买信用,如 Alex K 所述。
发送 SMS 的更好方法是使用 SMSLib 与蜂窝提供商的 SMSC 交互。然后,您还需要确保提供商能够将 SMS 路由到所有蜂窝网络。
关于从我的 Web 应用程序向印度的任何手机发送短信的 Java 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7403407/