Solved

How to send sms through C# application

Posted on 2013-02-04
7
2,065 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax error 9 45
Remove greater than sign 3 45
Angular JS Route 3 52
Export import database 4 43
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

12 Experts available now in Live!

Get 1:1 Help Now