Solved

How to send sms through C# application

Posted on 2013-02-04
7
2,010 Views
Last Modified: 2013-02-19
I have an application, that contains the Grid, which further contains the mobile no.s and Message.
On button click, i want the corresponding messages to be sms to every mobile no.

1. What are the things i need for this as the application is build in C#
2. Do i need the sms gateway server.
3. Is there free sms gateway server.
0
Comment
Question by:searchsanjaysharma
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 22

Assisted Solution

by:plusone3055
plusone3055 earned 200 total points
ID: 38850929
here is an article that explains in detail  w/code  :)

http://www.codeproject.com/Articles/19023/Sending-SMS-using-NET
0
 
LVL 22

Assisted Solution

by:plusone3055
plusone3055 earned 200 total points
ID: 38850940
0
 
LVL 10

Assisted Solution

by:Monica P
Monica P earned 200 total points
ID: 38853905
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:searchsanjaysharma
ID: 38854026
None is working
0
 
LVL 10

Assisted Solution

by:Monica P
Monica P earned 200 total points
ID: 38854146
0
 
LVL 9

Accepted Solution

by:
Orcbighter earned 100 total points
ID: 38864287
1. Just create a console application. See below
2. Do i need the SMS gateway server.
No. That will be provided by the company you subscribe to (see point 3)

3. There is no such thing as a free SMS service.
You have to choose a provider who will give you a gateway address. You can then use this to send your SMS texts to people.
These providers require a subscription (usually reasonable), which will allow you to send any number of SMS messages one at a time. If you want to be able to send texts to groups of numbers, that will probably cost more.

I wrote a program to send SMS messages to various mobile phones and found Clickatell to have a very easy to use API.
https://www.clickatell.com/
Check them out.

Clickatell is quite good. You get 10 free messages to test your code and then you can buy some subscriptions.
So, download their document describing their API and:

1. Create a simple console application.
2. Create a method called GetPhoneNumbers that returns a hard-coded list of mobile phone numbers). I used mine and my brothers (much to his annoyance).
3. Create a method called SendSMSText. Inside use a WebClient object and load up the properties of WebClient with your subscriber details, the desired phone number, and the text you want to send.

done.

Here is a simple test harness
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;


namespace SendSMS
{
    public class SendSMSApplication
    {
        string m_userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
        string m_baseURL = "http://api.clickatell.com/http/sendmsg";
        string m_username = "xxxxxxxxxxx";
        string m_password = "yyyyyyyy";
        string m_ap_id = "8888888";

        public SendSMSApplication()
        {
        }

        bool GetPhoneListForRule( int ruleID, ref List<string> phoneNumbers )
        {
            bool bRetStatus = true;

            phoneNumbers.Add( "22222222222" );
            phoneNumbers.Add( "33333333333" );

            return bRetStatus;
        }

        bool SendSMSText( List<string> phoneNumbers, string msgText )
        {
            bool bRetStatus = true;
            WebClient client = new WebClient();
            string multipleNumbers = String.Join( ",", phoneNumbers.ToArray() );

            client.Headers.Add( "user-agent", m_userAgent );
            client.QueryString.Add( "user", m_username );
            client.QueryString.Add( "password", m_password );
            client.QueryString.Add( "api_id", m_ap_id );

            //client.QueryString.Add( "to", "61412594784,61409595285" );
            client.QueryString.Add( "to", multipleNumbers );
            //client.QueryString.Add( "text", "This is an example message" );
            client.QueryString.Add( "text", msgText );

            using ( Stream data = client.OpenRead( m_baseURL ))
            {
                using ( StreamReader reader = new StreamReader( data ))
                {
                    string str = reader.ReadToEnd();
                    Console.WriteLine( str );
                }
            }

            return bRetStatus;
        }

        public void Run()
        {
            bool bAll_OK = true;
            List<string> phoneList = new List<string>();
            int ruleID = 24;

            bAll_OK = GetPhoneListForRule( ruleID, ref phoneList );

            if ( bAll_OK )
            {
                bAll_OK = SendSMSText( phoneList, "Hello World. This is a test message." );
            }
        }
    }
}

Open in new window

0
 

Author Closing Comment

by:searchsanjaysharma
ID: 38908274
tx
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now