How to Integrate SMS gateway in ASP.Net 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.

Send SMS using C#.NET

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 any of the SMS service provider available across the globe.

Integrate SMS gateway in ASP.Net website


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

Below is the C# code to send SMS

protected void btnSendSMS_Click(object sender, EventArgs e)
        SendSMS(txtMobile.Text.Trim(), txtSMS.Text.Trim());
    public 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);

You can simply integrate above SMS API Code to your website or app.

Keep following SharePointCafe.Net for upcoming blogs.

Leave a Comment