开发者

Java Code to send SMS from my Web Application to any Mobile in India

I have a requirement where I need to send SMS from my Web Application to any Mobile in India .

I got below code from a ipipi.com website:

I want to implement this functionality, could anybody please help me what values are to be provided here:

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();
      }
}


If the code above is linking to a service that converts incoming Email messages to outgoing SMS messages, you presumably need to purchase credit as stated by Alex K.

A better way to send SMSes would be to use SMSLib to interface with a cellular provider's SMSC. You also then need to make sure that provider is able to route SMSes to all cellular networks.


Your question seems specific to some service provider/API. But I would like to give a generic answer here.

Sending SMS need a SMS gateway to a SMSC. There are two simple methods[of-cause more can be]. You can either use your SIM card[SMS enabled], or use someone else's SIM card. SIM card provides connection to a SMS gateway through your service provider with SMSC.

Either ways, sending SMS is not free.Others may say its LIKELY free, but at-least an advertisement or a long term business marketing strategy must be there.

The way you are continuing is using someone else's SIM through an API provided by them. Since those have dedicated bulk SMS accounts, it may faster, multiple threaded, service. They should commercially helpful to you to get your problem sorted.

If you want to send SMS from your SIM, you have to connect your SIM to computer and use an standard API to call SMS functionality. SMSLib is what I suggest. You need a hardware to connect your SIM to PC, either connect your mobile to it or, use a Data Modem[easy] and interface through a COM port.

Try this code here, if you want to try your own SMS gateway.


First create an account in ipipi.com and validate it by clicking the activation link sent to the mail.And give your username as YoureIPIPIUsername and password as YourPassword.

String smtphost = "ipipi.com"

String compression = "Compression Option goes here - find out more";

There are some compression types here if u don't want anything you can mention "None"

String from = "YoureIPIPIUsername@ipipi.com"
String to = "DestinationPhoneNumber@sms.ipipi.com";

Destination ph number should be +91 and the 10 digit number

String body = "Your Message";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜