Your personal SMS Gateway with C#
Today I will describe simple but effective way to send sms from your computer using your mobile phone and a short C# application. I’m using Nokia 6070 but I guess any phone which has the ability to send SMS through AT commands will do.
First of all you would have to have a mobile phone connected to the computer through a cable and a driver for this cable installed. You need a driver to transfrom your usb cable into a serial interface.
To check if your phone is able to send sms using AT Commands please visit the following link and test it through the hyper terminal.
Once this is working you can easily do the same using C# and SerialPort class.
Here is a complete source which will transform your computer into your personal SMS Gateway:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading;
namespace SMSSender
{
class Program
{
static SerialPort p9 = new SerialPort("COM9", 9600);
static void Main(string[] args)
{
p9.DataReceived += new SerialDataReceivedEventHandler(p9_DataReceived);
p9.Open();
p9.Write("ATrn");
Thread.Sleep(500);
p9.Write("AT+CMGF=1rn");
Thread.Sleep(500);
p9.Write("AT+CMGS="123456789"rn");
Thread.Sleep(500);
p9.Write("!personal gateway!n");
Thread.Sleep(500);
p9.Write("Hello Worldx1Arn");
p9.Close();
}
static void p9_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
Console.WriteLine("Data received.." + p9.ReadLine());
}catch(Exception ex){
}
}
}
}
“123456789” stands for the mobile phone number where you want to send SMS to, and ‘x1A’ is a replacement for
Enjoy!
p9.Write(“AT+CMGS=”123456789″rn”);
I am getting error here! u cant use 2 set of double quotes here.suggest please
There must be a problem with my code formatting, as the error description says, you either have to concatenate the string or escape the quotes
hello
I am oing website with sms gateway.I would like to develop my own gateway.Any one have idea about this means pls share with me.
You need to concatenate the both strings, as :
p9.Write(“AT+CMGS=”+123456789+”rn”);
then it should work fine.
nicely put my friend , i wish i could of came up with such an eliquent way of putting it