Java代码将我的Web应用程序发送短信发送到印度的任何移动设备

5 java jakarta-mail

我有一个要求,我需要从我的Web应用程序发送SMS到印度的任何移动.

我从ipipi.com网站获得以下代码:

我想实现这个功能,任何人都可以帮助我在这里提供什么值:

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";
Run Code Online (Sandbox Code Playgroud)

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();
      }
}
Run Code Online (Sandbox Code Playgroud)

mcf*_*gan 1

如果上面的代码链接到将传入电子邮件消息转换为传出 SMS 消息的服务,您可能需要按照 Alex K. 的说明购买积分。

发送 SMS 的更好方法是使用 SMSLib 与蜂窝提供商的 SMSC 进行交互。然后,您还需要确保提供商能够将短信路由到所有蜂窝网络。