RunCodes
Programming & Tech

How to Send Free SMS From ASP.NET using SMS API?

1 2,609

As you all know guyz, the era that we are living is an era of internet, so everyone is hanging on their PC all the time. Everyday we are sending some SMS to our friends in order to inform something to them. So, if there is some method that can send SMS for free, everyone gonna use that method and loved it. Today, in this tutorial we are gonna discuss about that method but we are gonna send that message using our own program (ASP.NET). And also if you wanna send the message to your friends without displaying your number and name, this tutorial is for you! sometime we are in the mode of cracking jokes and wanna fool your friends or sending some threatening message(only for entertainment purpose otherwise it will be illegal) you can use this method.

“This tutorial may be very useful for those who want to integrate SMS features in their project which is developed in ASP.NET”.

For sending SMS using SMS API approach: you have to do two task:

1.   Selecting Carrier

2.    Writing code

we are selecting txtlocal as our carrier. So, All you have do is go to http://www.txtlocal.co.uk and there you need to create one account. after creating account. (you need to fill up some of your information and txtlocal will send you a verification email into your email and verify your account [watch the video for detail]). After completing this step, go http://api.txtlocal.com/docs/sendsms and from the select language option choose ASP.NET and then copy the code and edit as in the following manner or simply copy the following code but you need to provide your own api key when you run this project.

After doing this, you complete the task of selecting your carrier. Now write the following piece of code after designing the following form in Visual Studio.

STEPS:

[sociallocker]

1. I am assuming that you have Visual Studio, Open your Visual Studio and click on File>new project, From the left side of your window, select Visual C#>Web and select ASP.NET Web Application and then give the name of your web application click OK. Then new window will appear choose Empty and click OK.

2. Right click over your project and click on Add and select Web Form, give the name of your Web Form and click OK. Now, Inside the Body tag of the HTML write the following code:


<form id="form1" runat="server">
<div>
<div align="center"><caption><h1>SMS API</h1></caption></div><br />
<table align="center">

<tr>
<td>API Key</td>
<td>
<asp:TextBox ID="txtAPI" runat="server" Width="150px"></asp:TextBox></td>
</tr>
<tr>
<td>Sender Name</td>
<td>
<asp:TextBox ID="txtSender" runat="server" Width="150px"></asp:TextBox></td>
</tr>
<tr>
<td>Phone Number</td>
<td>
<asp:TextBox ID="txtPhone" runat="server" Width="150px"></asp:TextBox></td>
</tr>
<tr>
<td>Message</td>
<td>
<asp:TextBox ID="txtMessage" runat="server" Columns="10" Rows="5" TextMode="MultiLine" Width="150px"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td align="right">
<asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" /></td>
</tr>
</table>

</div>
</form>

After writing the above code your form should look like following one. To view how your code look like click click on Design or run in Web Browser.

How to Send Free SMS From ASP.NET using SMS API?

NOTE: To run your webapp in your browser, you need to install ISS. So, go to control panel>program and features and at the top right you may see turn windows features on or off and click Internet information services and click OK. Now you can execute your web apps in your browser.

3. Now double click that send button and you will jump to the yourform.aspx.cs file scroll up and include the following namespace.

using System.Net;
using System.IO;

4. Write the following piece of code inside the clicking event of Send Button:

string apiKey = txtAPI.Text;
string senderName = txtSender.Text;
string Number = txtPhone.Text;
string Message = txtMessage.Text;
string URL = "https://api.txtlocal.com/send/?apikey=" + apiKey + "&amp;sender=" + senderName + "&amp;numbers=" + Number + "&amp;message=" + Message;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string results = sr.ReadToEnd();
Response.Write(results);
sr.Close();
}
catch (WebException wex)
{
Response.Write("SOMETHING WENT AWRY! Status: " + wex.Status + "Message: " + wex.Message + "");
}

5. Now Login to the your txtlocal account, goto setting>API KEY and then click on create API Key and then simply copy that created key.

6. Run your project by clicking in that play button. Input your API Key, Sender Name, Phone number with country code in the respective textbox and then click on Send button. That’s it.

May be after sending 10 SMS your credit will be finished! but don’t be sad you can send more and more SMS but you need to create another account with another email account in www.txtlocal.co.uk ! that’s it. you may not be that much happy to hear this (sending only 10 SMS) but don’t forget you are able to send these 10 SMS for free and also there is one line “To get something, you must lose something”. it means you have to spend some time in creating account in txtlocal.co.uk in order to send free SMS.

[/sociallocker]

Finally, if you guyz think, this is awesome tutorial and help you in some extend please share this tutorials with your all friend so that they can know about this method of sending SMS!

if you have any confusion, you can watch the following video:

Show Comments (1)