Send SMS to a Mobile Phone Using C#

This example shows how to send SMS to a mobile phone using C#.


public void SendSMS(stirng msg, string mobileno)
{
///SMS GATEWAY PROVIDER PATH
string url = "http://XXXXProvider.com?phoneNumber={0}&MsgTxt={1}";

string url1 = String.Fomat(url, mobileNo, msg);

//create Web Request object for the url
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url1);

// get the response from the web request
HttpWebResponse res = (HttpWebResponse)req.GetResponse();

// read the response from the WebResponse in to a stram
Stream s = res.GetResponseStream();
StreamReader rdr = new StreamReader(s);
string result = rdr.ReadLine();
s.Flush();
s.Close();
}


Comments

Author: Fool To Code01 Dec 2008 Member Level: Gold   Points : 2

for asp.net see this code:

Dim XMLHttp, DataToSend, PostUrl
DataToSend = ""
PostUrl = "http://www.your sms provider name.com"
DataToSend = DataToSend & "?sername=username"
DataToSend = DataToSend & "&pass=password"
DataToSend = DataToSend & "&senderid=senderid"
DataToSend = DataToSend & "&dest_mobileno=" & dgitem.Cells(2).Text & ""
DataToSend = DataToSend & "&message=" & txtMessage.Text & ""
PostUrl = PostUrl & DataToSend
XMLHttp = Server.CreateObject("MSXML2.XMLHttp")
XMLHttp.Open("GET", PostUrl, False)
XMLHttp.setRequestHeader("Content-Type", "application/x-www-form- urlencoded")
XMLHttp.send("")

Author: Fool To Code01 Dec 2008 Member Level: Gold   Points : 2

for desktop application:

Dim baseurl As String=write complete string as given by your provider
Dim data As Stream = client.OpenRead(baseurl)
Dim reader As StreamReader = New StreamReader(data)
Dim s As String = reader.ReadToEnd()
data.Close()
reader.Close()
'Return
MessageBox.Show("message sent")

Author: KR12 Dec 2008 Member Level: Gold   Points : 0

Hi,

Veery useful code..

Regards
Vijay

Author: Deepika Haridas15 Dec 2008 Member Level: Gold   Points : 0

Good useful code..
Thanks for posting..

Regards,
Deepika

Author: Sayre25 May 2009 Member Level: Gold   Points : 0

Hi, thanks for posting.

Guest Author: raju19 Jul 2012

hi ,
how can i get sms provider please helo me............

Guest Author: salehi2030 Jan 2013

can you description about this any more?



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: