Tuesday, November 18, 2008

how to send sms to mobile in asp.net(C#)

You should get the API from SMS gateway box manufacturer.


Visit this might shed a light on it.

http://www.ozekisms.com/index.php?owpn=230

http://www.smsxchange.com/main/default.asp

It also has been discussed here.

http://forums.asp.net/t/1193672.aspx


1. First of all you should have the SMS Package for sending SMS

2. Suppose if you've then right click on application in VS and select Add Web Referrence...

3. You've to add this in Web Config AppSettings



add this in u r code or you can customize in your own way




private bool SendSms(string mobileNo)
{
try
{
mobileNo = "Internation Code 1" + mobileNo.Substring(1, mobileNo.Length - 1);
BulkSingleSend mySms = new BulkSingleSend();
Boolean ServiceStatus = mySms.IsServiceAlive();
string smsBody = System.Configuration.ConfigurationManager.AppSettings["smsbody"].ToString();
string result = mySms.SendSMS("From", "Subject", mobileNo.Text, TextBox1.Text);
return true;
}
catch
{
return false;
}
}



Note: When you add Web Referrence in your Application you'll find three new files with extention .disco, .wsdl, .discomap extention files.

private void Send_Click(
object sender, System.EventArgs e)
{
try
{
SmsTest.net.webservicex.www.SendSMS smsIndia=
new SmsTest.net.webservicex.www.SendSMS();
SmsTest.com.webservicex.www.SendSMSWorld smsWorld =
new SmsTest.com.webservicex.www.SendSMSWorld();
if(rdoType.SelectedValue == "1")
smsIndia.SendSMSToIndia(txtMobileNo.Text.Trim(),
txtEmailId.Text.Trim(), txtMessage.Text);
else
smsWorld.sendSMS(txtEmailId.Text.Trim(),
txtCountryCode.Text.Trim(), txtMobileNo.Text.Trim(),
txtMessage.Text);
lblMessage.Visible = true;
lblMessage.Text="Message Send Succesfully";
}
catch(Exception ex)
{
lblMessage.Visible = true;
lblMessage.Text="Error in Sending message"+ex.ToString();
}
}

No comments: