Nowadays, it is a big question for every novice programmer to develop an application that sends an SMS to any mobile throughout the world. In my first internship, I was asked to develop such an application. I tried & I am finally done.
Using the Code
To use the SMS code is quite simple though it looks quite irritating. I had managed the code in separate files to avoid confusion as well as conflict in using the code.
First of all, I have to develop an interface where the user can put his contact number and message and send it. So for that, I created an interface.
Then it's time to provide SMS functionality to the given interface. For that, I had created sms.cs in the app_code directory as:
public class SMS
private const string sms_username = "username";
private const string sms_password = "password";
private const string sms_SenderName = "LMVJAY";
public string responseFromServer;
public string PostRequestSMS(string message, string mobileno)
string msg = "username=" + sms_username + "&password=" +
sms_password + "&sendername=" + sms_SenderName +
"&mobileno=" + mobileno + "&message=" + message;
WebRequest request = WebRequest.Create
sms_SenderName+"&mobileno=" + mobileno + "&message=" + message);
request.Method = "POST";
string postData = msg;
byte byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader readerst = new StreamReader(dataStream);
responseFromServer = readerst.ReadToEnd();
Now, I am ready to call a method
PostRequestSms and pass parameter.
So in codebehind on button click event, I fired this code.
public partial class _Default : System.Web.UI.Page
SMS objSMS = new SMS();
protected void Page_Load(object sender, EventArgs e)
protected void btnSend_Click(object sender, EventArgs e)
Now it's almost done. You have to simply build your project and run and send SMS.
Points of Interest
Sending an SMS via ASP.NET for the first time was a challenge for me. There are various methods to send SMS using ASP.NET, but I find this method somewhat easy.
Before sending an SMS, you have to register an API. I use dove API. So in order to send an SMS, you have to register API.