How to send SMS in C# using SMS CHUB

 This sample code let you send SMS to any Indian mobiles.

Api URL will look like "<smschub-base-url>/api/sms/format/json" or "<smschub-base-url>/api/sms/format/xml"
 
 public static bool Send(string mobileNo, string message)
        {
            try
            {
                string sms = HttpUtility.UrlEncode(message);

                if (!string.IsNullOrWhiteSpace(<url>))
                {              
                    try
                    {
                        var parameters = new NameValueCollection();
                        parameters["sender"] = <sender-id> ;
                        parameters["mobile"] = <mobile-number>;
                        parameters["route"] = <route>;
                        parameters["text"] = message;
                        using (var client = new WebClient())
                        {
                            client.Headers.Add("X-Authentication-Key", <your api key>);
                            client.Headers.Add("X-Api-Method", <method>);
                            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                            byte[] response = client.UploadValues(URL, "POST", parameters);
                            string responseStr = Encoding.UTF8.GetString(response);
                            Console.WriteLine(responseStr);
                        }               
                    }
                    catch { }
                    return true;
                }
            }
            catch { }
            return false;
        }


If you have any doubts please comment it below.

Comments

  1. The developed API and ready made scripts by technical team of Msgclub, it is easy to integrate in any software developed in C#.
    c# sms gateway integration

    ReplyDelete

Post a Comment