Java Code To Send SMS Using Sms Gateway

Do you know why we need Java code? Well, we use Java code to create web applications. Now you can use Java code to send SMS using an SMS gateway. Essentially, developers and producers these days use Java code to create applications for computers. So, if you are considering how to advertise your business, use computers and mobile phones to do so. Almost everyone uses these two electronic gadgets, as they have become necessities in our daily lives.

Java code – Simple send SMS example


import no.vianett.sms.SmsEventListener;
import no.vianett.sms.Sms;
import no.vianett.sms.SmsEvent;
import no.vianett.sms.component.SmsTransceiver;
import no.vianett.sms.log.SmsScreenLogger;
import no.vianett.sms.event.SmsDeliveredEvent;
import no.vianett.sms.event.SmsSendingFailedEvent;
import no.vianett.sms.event.SmsDeliveryFailedEvent;
public class SmsSender implements SmsEventListener
{
    private SmsTransceiver transceiver = null;
    private Object link = null; // Just to keep this object alive.
    private int counter = 0;
    public SmsSender()
    {
        this.link = this; // Keeps this object alive.
        this.transceiver = SmsTransceiver.getInstance(); // Get the transceiver object.
        // Initialize transceiver.
        String smsHost = “cpa.vianett.no”;
        String smsPort = “31337”;
        String smsUsername = “username”;
        String smsPassword = “password”;
        this.transceiver.initialize( smsHost, Integer.parseInt( smsPort ), smsUsername, smsPassword, newSmsScreenLogger() );
        this.transceiver.addSmsEventListener( this ); // Registrer this class as listener for SMS events.
        // Send message
        Sms sms = new Sms();
        sms.setId( ++this.counter );
        sms.setReplyPath( 100 );
        sms.setSender( “1963” ); // Set the sender number.
        sms.setMessage( “Hello World!” );
        sms.setRecipient( “xxxxxxxx” ); // The recipients phone number.
        this.transceiver.send( sms );
    }
    // Just make new instance of this class.
    public static void main( String[] args ){ new SmsSender(); }
    /**
    * Listener.
    *
    * @param event a <code>no.vianett.sms.SmsEvent</code>
    */
    public void eventHappened( SmsEvent event )
    {
        if( event instanceof SmsDeliveredEvent )
        {
            System.out.println( “Sms delivered.” );
            System.out.println( “Refno : ” + event.getReferenceId() );
            System.out.println( “Sms generated by : ” + event.getSource().getClass() );
        }
        else if( event instanceof SmsSendingFailedEvent )
        {
            System.out.println( “Sms sending failed.” );
            System.out.println( “Refno : ” + event.getReferenceId() );
            System.out.println( “Return code : ” + ( ( SmsSendingFailedEvent ) event ).getReturnCode() );
            System.out.println( “Sms generated by : ” + event.getSource().getClass() );
        }
        else if( event instanceof SmsDeliveryFailedEvent )
        {
            System.out.println( “Sms delivery failed.” );
            System.out.println( “Refno : ” + event.getReferenceId() );
            System.out.println( “Error code : ” + ( ( SmsDeliveryFailedEvent ) event ).getErrorCode() );
            System.out.println( “Sms generated by : ” + event.getSource().getClass() );
        }
    }
}

Source: vianett.com/en/developers/api-code-examples/java

Sending SMS through the internet is an excellent option these days. All you need is a computer or laptop and a reliable internet connection. As a business owner, you can send SMS to your existing customers regardless of your location, without being restricted within a certain boundary.

By using the internet, you can find thousands of people’s phone numbers and turn them into potential customers. Ensure you provide excellent service, especially if you’re new to this field. Many businesses offer similar products or services, but if you are honest and reliable, your customers will stay loyal.

If you’re thinking of offering special discounts, send SMS through the internet to inform your existing customers. Notify them a few days in advance so they can come to you and avail of the discount. Wish your customers on their birthdays or special occasions to stay connected and make them feel valued.

People enjoy receiving messages on festive days, and they are more likely to visit your business upon seeing your messages. If possible, address your customers by their first names to create a more personal connection.

Since most businesses have internet connections in their offices, there is no need to pay extra money. This method is the easiest, cheapest, and most reliable way to market a product. If you are launching a new product or service, just send an SMS to people, and they will learn about it within seconds.

Calling someone unknown may not be well-received, or they might be occupied with something important. It is better to send a message to their inbox. When the recipient is free, they will take the time to read your message and, if relevant, likely respond.

Refrain from charging extra for a reply and always take feedback positively. The more your customers reply, the more you should be encouraged by their desire for your business to improve.

GET THE BEST APPS IN YOUR INBOX

Don't worry we don't spam

Login/Register access is temporary disabled