Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to send sms through C# application

Posted on 2013-02-04
7
Medium Priority
?
2,425 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 400 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 400 total points
ID: 38850940
0
 
LVL 10

Assisted Solution

by:Monica P
Monica P earned 400 total points
ID: 38853905
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Assisted Solution

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

Accepted Solution

by:
Orcbighter earned 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

971 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