Send SMS using C#. Integrate SMS gateway in asp.net website

In this blog I will write about sending SMS using C# code.
You all must have receive SMS related to OTP (One Time PIN) on your mobile for various kind of transactions from different websites or App.

Here I will provide the C# code which you can use to send SMS to your customers/users from your website or App.

Before using below C# code, you need a bulk SMS plan to send SMS.
There are so many bulk SMS providers in the market.
You may buy Bulk SMS from IndiaSMS.Com  - http://www.indiasms.com/

Below is the C# code to send SMS | Integrate SMS gateway in ASP.Net website


ASPX Code:

<div>
        Customer Mobile No.
        <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
        <br />
        Enter Your SMS
        <asp:TextBox ID="txtSMS" TextMode="MultiLine" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="btnSendSMS" runat="server" Text="Send SMS" OnClick="btnSendSMS_Click" />
    </div>

C# Code

protected void btnSendSMS_Click(object sender, EventArgs e)
    {
        SendSMS(txtMobile.Text.Trim(), txtSMS.Text.Trim());
    }

    private string SendSMS(string customerMobileNumber, string smsContent)
    {
        WebClient webClient = new WebClient();
        webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
        webClient.QueryString.Add("username", "<username>");
        webClient.QueryString.Add("password", "<password>");
        webClient.QueryString.Add("type", "TEXT");
        webClient.QueryString.Add("sender", "<sender id>");
        webClient.QueryString.Add("mobile", customerMobileNumber);
        webClient.QueryString.Add("message", smsContent);
        string rawUrl = "<sms-api-url>";
        Stream smsData = webClient.OpenRead(rawUrl);
        StreamReader reader = new StreamReader(smsData);
        string sReader = reader.ReadToEnd();
        smsData.Close();
        reader.Close();
        return (sReader);
    }



Comments

Popular

SharePoint Interview Questions and Answers

Calling ASP.Net WebMethod using jQuery AJAX

What is Cloud Computing - A guide for beginners

How to Crop and Upload image using JQuery