Solved

How to send sms through C# application

Posted on 2013-02-04
7
2,194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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 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

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!

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

756 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