Labels

slider

Recent

Navigation

SMS API: How to send SMS using C#

send sms using c#, send sms using c# windows application, send sms using c# gsm modem, send sms using c# asp.net, send sms using c# MVC

Introduction

SMS stands for Short Message Service is widely used to communicate to another mobile devices. Earlier, provided resolution to resolve issue Authentication the Server Response was 5.5.1 Authentication required in gmail, now today explaining how to send SMS using C#. We can send SMS up to 160 characters through our mobile devices. Long message can split up into small multiple parts automatically. On mobile device can send text message only. Here, I am exposing how to send text SMS (Short Message Service) using c# code.
  1. First of all. We need to create an URL to send text message on mobile device.
  2. We require web or IP address with parameters like username, password, recipient, senderid, text message and response etc.
  3. Parameters can vary depend on SMS provider service. Providers provide complete information to send SMS.
  4. Now we need to create web request to send SMS using C# code.
  5. We can also track response after sending text message on mobile device.
SMS API
Fig: SMS API

Code Snippet


public ActionResult SendSMSInCsharp()
{
    //we creating the necessary URL string:
    string _URL = "192.168.1"; //where the SMS Gateway is running
    string _senderid = "TESTTC";   // here assigning sender id 
            
    string _user = HttpUtility.UrlEncode("TestSMS"); // API user name to send SMS
    string _pass = HttpUtility.UrlEncode("123456");     // API password to send SMS
    string _recipient = HttpUtility.UrlEncode("9999999999");  // who will receive message
    string _messageText = HttpUtility.UrlEncode("testing sms..."); // text message

    // Creating URL to send sms
    string _createURL = _URL + 
    "username =" + _user +
       "&pass=" + _pass +
       "&senderid=" + _senderid +
       "&dest_mobileno=" + _recipient +
       "&message=" + _messageText;

    try
    {
        // creating web request to send sms 
        HttpWebRequest _createRequest = (HttpWebRequest)WebRequest.Create(_createURL);
        // getting response of sms
        HttpWebResponse myResp = (HttpWebResponse)_createRequest.GetResponse();
        System.IO.StreamReader _responseStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
        string responseString = _responseStreamReader.ReadToEnd();
        _responseStreamReader.Close();
        myResp.Close();
    }
    catch
    {
        //
    }
    return View();
}

Conclusion

SMS (Short Message Service) is now used across the world through mobile devices to instant communication medium. In this article, demonstrated explained all steps to send SMS using C# code. You can send SMS through this code in ASP.Net, MVC using C# code.

Suggested Reading

Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

16 comments:

  1. I have gateway uc100, i want connect to send sms in c#. Can you help me?

    ReplyDelete
    Replies
    1. yes, can you send your all required information senderURL, username, password etc. to my emailID kantanjan@gmail.com if are you still facing problem.

      Delete
  2. Please use this Document & help to create in c# with SMSGATEWAYHUB

    https://www.smsgatewayhub.com/Panel/WebAPI/HTTP%20API%203.0.1%20-%20SMSGATEWAYUHB.pdf

    ReplyDelete
  3. SMS services like bulk sms, transaction sms, promotional sms, SMS API, OTP, QTP, are great strategy to work with huge number of clients. It helps in maintain a good relation with clients. you can select Top 5 Bulk SMS Service Provider in India with SMS API for your business.

    ReplyDelete
    Replies
    1. how should i implement this module in my project using c#

      Delete
  4. Great article Anjan I personally use www.textlocal.in for promoting my business which has its API available for free and have a detailed explanation how to use their API to integrate to a website or a app.

    ReplyDelete
    Replies
    1. sir can you help to implement this module in my project

      Delete
    2. yes, I can help you where are you getting problem. can you detail your problem here.

      Delete
  5. hi Anjan Kant,
    Can this piece of code work for any sms geteway
    (I have requirement where I don't want to restrict my client to use only fixed sms gateway, means he can plug any sms gateway as his choice.) what to do?

    thanks
    sushil bhat

    ReplyDelete
    Replies
    1. It may be few variations from SMS provider to provider but in this code added standard part of SMS code. In India, we need also to include template ID (standard text from TRAI authorised).

      Delete
  6. Hey Anjan, thanks for writing this. Do you know what I was looking for some solution to send bulk SMS from one of my C# application and I got the answer here. Keep posting and helping, once again thanks for sharing.

    ReplyDelete
  7. hi, i want send email to gmail and sms to registration mobile number who is already registered. Using with mvs 5 3 tier architecture can you help me?

    ReplyDelete
    Replies
    1. yes, this code will work for you using MVC as well :)

      Delete
  8. Using this code , I am not able to send SMS

    ReplyDelete