joomla visitors
Mithila Software Blog | Sending SMS using SMPP sample code

Sending SMS using SMPP sample code

July 04, 2012 Posted by Mithila Software



There are many sms paid service providers which you can use in your applications either for user verfication or information update push to the end user.When you buy bulk sms pack from your provider they should provide

 

Host IP or Name ="xx.xx.xxx.xx" / xxx.com ;

Port = "xxxx";

User = "";

Password = "";

From = "";

 

The sample code provided by the providers are mostly in php or classic asp.An implementation of sms sending code in asp.net is expected to be like this

 

public void sendSMS (string strHost, string strPort,string strUser,string strPassword ,string strRecip,string strMsgText,string strFrom) 
{
Uri objURI =
new Uri("http://" +
strHost + ":" +
strPort+ "/?User=" +
HttpUtility.UrlEncode(strUser) +
"&Password=" + HttpUtility.UrlEncode(strPassword) +
"&PhoneNumber=" + HttpUtility.UrlEncode(strRecip) +
"&Text=" + HttpUtility.UrlEncode(strMsgText)
// The actual message that you send must be <=140 characters+
"&Sender=" + HttpUtility.UrlEncode(strFrom));
WebRequest objWebRequest= WebRequest.Create(objURI);
WebResponse objWebResponse = objWebRequest.GetResponse();
}

 


Now the above code is like fire and forget principle.In reality we may need the outcome of our send message.For that purpose we can modify the above code to return the outcome of our sent sms.

 

public string sendSMS (string strHost, string strPort,string strUser,string strPassword ,string strRecip,string strMsgText,string strFrom) 
{
Uri objURI =
new Uri("http://" +
strHost + ":" +
strPort+ "/?User=" +
HttpUtility.UrlEncode(strUser) +
"&Password=" + HttpUtility.UrlEncode(strPassword) +
"&PhoneNumber=" + HttpUtility.UrlEncode(strRecip) +
"&Text=" + HttpUtility.UrlEncode(strMsgText) +
"&Sender=" + HttpUtility.UrlEncode(strFrom));
WebRequest objWebRequest= WebRequest.Create(objURI);
WebResponse objWebResponse = objWebRequest.GetResponse();
Stream objStream= objWebResponse.GetResponseStream();
StreamReader objStreamReader = new StreamReader(objStream);
String strHTML = objStreamReader.ReadToEnd();
return strHTML;
}

 


So , the above code is supposed to return a string result of our send sms.

Tags:

Asp.Net

blog comments powered by Disqus
Address ::
Mithila Software Solutions,
Green House , 3 GM Road ,
Near Radio Station , Darbhanga
PIN:: 846004
Phone :: # 099-397-49350