C# .NET - Sending sms through .Net C# Windows Application
Asked By Shreya Trivedi on 30-Jun-08 03:24 AM
I want to build a windows application that can send sms to the mobile nos selected by user. The message has to be fetched from a table of Sql server 2005 database. The sms should be sent in 2 ways-
1) Through sms gateway
2) Through H/W (modem,GSM etc.)
Please send me code for sending sms in C#.Net in both the above mentioned ways. Thanks in advance.
Sending sms through .Net C# Windows Application - Sat Sat replied to Shreya Trivedi on 30-Jun-08 03:33 AM
Hi,
ans to your first question
using System.Net;
HttpWebRequest request = WebRequest.Create("http://www.sms.ac?mobileno=91989000989000&msg=Hi+there");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd() // This will contain the status of message e.g. failed, ok etc.
Ans. 2
You need to buy third party library developed for sending sms using your deveice
SAtalaj
Sending sms though C# .NET Window Application - SP replied to Shreya Trivedi on 30-Jun-08 04:00 AM
I think the best option is to use an SMS Gatway, that supports C#. The following article gives you more information about this:
http://
Also refer this article with source code ::
http:// (Helpful)
Hope it helps.
check this - Santhosh N replied to Shreya Trivedi on 30-Jun-08 04:11 AM
Check this link for detailed explaination on how to go about your requirement of sending SMS in .Net using SQL server too...
http://www.codeproject.com/KB/database/SMS_message_from_SQL.aspx
You will find useful information for sending sms here below - Sakshi a replied to Shreya Trivedi on 30-Jun-08 04:15 AM
forums.msdn.microsoft.com/en/csharpgeneral/thread/f1cbd130-f248-4349-8f1d-4ecc0ca65349/
http://www.logixmobile.com/products/mcorelib/index.asp
http://www.activexperts.com/xmstoolkit/howto/smpp/vcnet/
groups.google.com.fj/group/DotNetDevelopment/msg/f96f900aa601728d
Following error is produced by implementing the code you gave - Shreya Trivedi replied to Sat Sat on 30-Jun-08 04:37 AM
System.Net.WebException was caught
Message="The remote server returned an error: (403) Forbidden."
Source="System"
SMS api C# integration - Sat Sat replied to Shreya Trivedi on 30-Jun-08 06:25 AM
Hi,
The url I have given is "http://www.sms.ac?mobileno=91989000989000&msg=Hi+there" Demo url. It dosen't exist at all.
This is a step that you need to follow after purchasing the Bulk SMS credit from third party like sms.ac.
There are so many bulk sms API provider in the market choose one for you.
read their documnets for parmeter list they accept via POST or GET method
Satalaj
Sending sms through .Net C# Windows Application - Swapnil Salunke replied to Shreya Trivedi on 30-Jun-08 07:05 AM
Hello Shreya
There are two ways to send an sms through .net
One way is to use the webservice which offers their Built in APIs using that you can able to send the SMS
Using the SMS Gateway also you can able to send the sms
refer this link
http://www.codeproject.com/KB/database/SMS_message_from_SQL.aspx
http://www.daniweb.com/forums/thread56125.html
http://www.ozekisms.com/c-sharp-sms-api/index_p_php_q_ow_page_number_e_315opt.html
how ever I have implemented it using the Modem connected to the Serial Port Using some AT Commands. this is the sample code of this I can give you more info if you want to go for it
sp.write(
AT_PREFIX + "+CMGS" + "=";)
byteWrite = System.Text.
Encoding.UTF8.GetBytes(msgdata);
i = byteWrite.Length;
Array.Resize(ref byteWrite, i + 3);
byteWrite[i] = (
Byte)26;
i = i + 1;
byteWrite[i] = (
Byte)10;
i = i + 1;
byteWrite[i] = (
Byte)13;
Sp.Write(byteWrite, 0, byteWrite.Length - 1);
Hope this helps you
Takecare Bye
Find here - Nadaraja Yogendran replied to Shreya Trivedi on 30-Jun-08 08:48 AM
Reply - alice johnson replied to Shreya Trivedi on 30-Jun-08 09:22 AM
private void button1_Click(object sender, EventArgs e)
{
try
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=SQLNCLI;Server=.\\;"+
"User ID=ozekiuser;password=ozekipass;Database=ozeki;Persist Security Info=True";
conn.Open();
if (conn.State == ConnectionState.Open)
{
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
string SQLInsert =
"INSERT INTO "+
"ozekimessageout (receiver,msg,status) "+
"VALUES "+
"('"+tbSender.Text+"','"+tbMsg.Text+"','send')";
cmd.CommandText = SQLInsert;
cmd.ExecuteNonQuery();
MessageBox.Show("Message sent");
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Hello you can go through this sites, it will help you better.
the above code is part of the coding in the site:
http://www.codeproject.com/KB/database/SMS_message_from_SQL.aspx
http://www.codeproject.com/KB/cpp/SendSmsThroughWS.aspx
Sending sms using modem connected to serial port using AT commands - Shreya Trivedi replied to Swapnil Salunke on 16-Jul-08 12:59 AM
Dear Swapnil,
You said that you have implemented sending sms using the Modem connected to the Serial Port Using some AT Commands. Can you please explain me this in detail? What are AT commands and what does "sp" refer to in the code you have given? I am totally new to this. So please explain me in detail regarding the implementation and hardware interfacing necessary for implementation. Thanks!
Sending sms using modem connected to serial port using AT commands - Swapnil Salunke replied to Shreya Trivedi on 16-Jul-08 05:27 AM
Dear Shreya
I think you need to setup the hardware required for this first then can implement it.
actually it is just through the simple modemn which is connected to the computer through the serial port and has a place to insert the simcard into it it also has one antena for the coverage. Now you need to simply run the commands on the serial port to read and send sms on simcard.
swapnilrsalunke@yahoo.co.in
mail me if you are intrested in setting up the required h/w setup and tell me the exact need so we can trace out how much it is feasible.
Happy Coding takecare
re - shweta k replied to Shreya Trivedi on 01-Dec-08 12:15 PM
Hi,
You can try these links
http://www.txtimpact.com/
http://www.wire2air.com/
They provide Active X as well as HTTP API.
Code for SMS - Deepak Dwivedi replied to Shreya Trivedi on 04-Feb-09 06:35 AM
I want to build a windows application that can send sms to the mobile nos selected by user. The message has to be fetched from a table of Sql server 2005 database. The sms should be sent in 2 ways-
1) Through sms gateway
2) Through H/W (modem,GSM etc.)
Please send me code for sending sms in C#.Net in both the above mentioned ways. Thanks in advance.
SAme code above will work for you - Asked By Sat Sat on 04-Feb-09 09:28 AM
you need to get third party API. Then integrate it with your system using HttpWebRequest and HttpWebResponse or WebClient found under Syste.Net namespace.
Sending SMS using C#.Net - Joseph John replied to Shreya Trivedi on 27-Sep-09 01:45 PM
I have added all the details in this blog
http://csharptechniques.blogspot.com/
aliceliu replied to alice johnson on 18-Jul-10 05:33 AM
how did u manage to successfully get connected from asp.net to database? im also using the same code from ozeki sms gateway but im having problem to connect to database. with the
"('"tbSender.Text+"','"+tbMsg.Text+"','send')";
part code error.
part code error.
below is my code:
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
namespace SMS_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//Connect to ozeki database
//Create and Open the Connection
OleDbConnection conn = new OleDbConnection(@"Data Source=ALICE-PC\SQLEXPRESS; Integrateg Security=SSPI; Initial Catalog=DB.mdf");
conn.ConnectionString = "Provider=SQLNCLI;Server=Alice-PC.\\;"+
"Database=ozeki;Persist Security Info=True";
conn.Open();
if (conn.State == ConnectionState.Open)
{
//Send the message
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
string SQLInsert =
"INSERT INTO "+
"ozekimessageout (receiver,msg,status) "+
"VALUES "+
"('"tbSender.Text+"','"+tbMsg.Text+"','send')";
cmd.CommandText = SQLInsert;
cmd.ExecuteNonQuery();
MessageBox.Show("Message sent");
}
//Disconnect from the database
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}