Send SMS using C#. Integrate SMS gateway in website

In this blog, I will write about How to send SMS using C# code.
You all must have received 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  -

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

ASPX Code:

        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" />

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();
        return (sReader);

Keep following SharePointCafe.Net for upcoming blogs.



What's new in C# 6.0 language - All new features of C# 6.0 for developers

SharePoint Interview Questions and Answers