RunCodes
Programming & Tech

How to Send Free SMS From C#.NET using SMS API?

2 4,230

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 (C#). 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 C#”.

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

1.   Selecting Carrier

2.    Writing C# 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 C# 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#>Window and from the middle side select Windows Forms Application and then give the name of your project and then click ok which is shown in below.

2. From the ToolBox Drag and Drop four label, four Textbox and one button in your form and change the properties of these controls by selecting each control and right click that particular control and click on properties.

Four Label for phone no, api key, sender, message
Four Textbox for phone no, api key, sender, message
one Button to send

NOTE: You can increase the message box large for this select message box textbox go to properties and then change the multiline to true and ScrollBars to Both and then expand this textbox by dragging it. The designed form look like:

3. Double click on the Send button to go to the .cs section of your project and scroll up and then add the following namespace to your program as:

using System;
using System.Collections.Generic;
using System.Net;
using System.Collections.Specialized;
using System.IO;

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


string result;
string apiKey = txtapi.Text;
string numbers = txtnum.Text; // in a comma seperated list
string message = txtmess.Text;
string send = txtseder.Text;
String url = "https://api.txtlocal.com/send/?apikey=" + apiKey + "&numbers=" + numbers + "&message=" + message + "&sender=" + send;
//refer to parameters to complete correct url string

StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = Encoding.UTF8.GetByteCount(url);
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(url);
}
catch (Exception ex)
{
//return e.Message;
MessageBox.Show(null, "the error is" + ex, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
myWriter.Close();
}

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
//return result;
MessageBox.Show(result);
}

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. if you want to send SMS using email2sms method read this tutorial : CLICK HERE

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 (2)