View Full Version : how to send SMS using asp.net
danielliu8
10-29-2004, 03:27 AM
I try to build a asp.net mobile application to send SMS to any cellular phone user. But only success to send SMS to TMobile user.
Can anyone tell how to send SMS to most cellular phone usersby using asp.net?
Any module, web services or 3rd party platform?
Thanks
Daniel liu
asp.net webdeveloper
www.DiamondBarWeb.com (http://www.DiamondBarWeb.com)
bruce
10-29-2004, 09:52 AM
I found some link on the Internet on this topic
http://www.aspnetpro.com/thirdparty/showfile.asp?FileID=1775
http://www.codeproject.com/aspnet/SendingSMS.asp
Hope this help
Bruce
DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)
danielliu8
10-29-2004, 10:20 AM
Thanks, Bruce,
Actually, I read these two articles this week by searching internet. Both not working:
There is no any valid link in http://www.aspnetpro.com/thirdparty/showfile.asp?FileID=1775. I can not see or download anything from this article.
http://www.codeproject.com/aspnet/SendingSMS.asp is a good article, butit's web services only works for 5 small Mobile providers. Can not send SMS to any big mobile providers like TMobile, Sigular, ATT..., so it is not good web service to send SMS in USA and Canada.
Is there any way to send SMS to most cell users in north america? either by free or paid web services, or can any .net programmer create a SMS gateway from asp.net?
thanks a lot for your feedback.
daniel liu
asp.net web developer
www.DiamondBarWeb.com (http://www.DiamondBarWeb.com)
bruce
10-29-2004, 10:57 AM
I could be wrong here as i have not done any sms programming, but I don't think you can create an SMS gateway
http://www.aspnetpro.com/thirdparty/showfile.asp?FileID=1775 has a link to the project file, click on smsmessage.zip
Also try search SalCentral for available SMS web service. I found a bunch of them there
http://www.abctext.com/user/main.aspx
Bruce
DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)
danielliu8
10-29-2004, 11:20 AM
thanks, Bruce,
http://www.aspnetpro.com/thirdparty/showfile.asp?FileID=1775 only has 2 broken links, can you get the zip file from the link?
I spend a lot of time searched both SalCentral for available SMS web service and http://www.abctext.com/user/main.aspxlast week, could notfind any useful web services.
Did you find any useful web services?
Thanks for help.
daniel liu
asp.net web developer
www.DiamondBarWeb.com (http://www.DiamondBarWeb.com)
bruce
11-01-2004, 07:59 AM
No sorry /emoticons/shakehead.gif
Bruce
DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)
mohda
11-06-2004, 10:38 AM
I think you can use one of the two companies below: (Using HTTP post or .dll componenet)
http://www.clickatell.com
http://www.aspsms.com
Currently i am using clickatell using http post in asp.net
mohda
11-10-2004, 07:22 AM
[quote]
Shared Function ClickatellPING(ByVal Session_ID As String) As Boolean
' Ping to make the connection live more
Try
MyURL = ""
MyURL = "http://api.clickatell.com/http/ping?session_id=" & Trim(Session_ID)
myHttpWebRequest = CType(WebRequest.Create(MyURL), HttpWebRequest)
'myHttpWebRequest.Proxy = proxyObject
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
streamResponse = myHttpWebResponse.GetResponseStream()
Dim streamRead = New StreamReader(streamResponse)
count = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
If outputData = "OK" Then
ClickatellPING = True
Else
ClickatellPING = False
End If
count = streamRead.Read(readBuff, 0, 256)
End While
' Close the Stream object.
streamResponse.Close()
streamRead.Close()
myHttpWebResponse.Close()
Catch ex As Exception
Call DBAddErrorLog(ex.Message, "ClickatellPING", "")
ClickatellPING = ex.Message
End Try</CODE>You can use the above code to send http request from .NET and you'll receive the reply and you can proccess the reply.
You can use the same with other http commands. Such as GetBalance SendSMS, ... ect
In clickatell you can find the in API Section HTTP Post.
Or you can use the Clickatell customer compnenet, but i don't think Discoundasp.com will allow to install this custom Componenet on there server.
danielliu8
11-10-2004, 12:10 PM
Thanks,
I checked http://www.clickatell.com (http://www.clickatell.com/)and registered, but did nto find a way to send SMS from my asp.net application, would you please tell detail howuse clickatell http post in asp.net? Is it a xml web services or com object?
Thanks a lot.
daniel liu
asp.net web developer
www.DiamondBarWeb.com (http://www.diamondbarweb.com/)
danielliu8
11-30-2004, 04:23 AM
Thanks a lot, Mohda,
sorry that I was busy with a another deadline project which just finished yesterday.
Thanks for your code,questions to your code:
1.
How can I send my custom SMS title and message from your code? I did not find any to,cc,bcc, title, body... property in your code.
2.
How can I get valid "Session_ID"?
thanks a gain for your help.
daniel liu
asp.net web developer
www.DiamondBarWeb.com (http://www.diamondbarweb.com/)
mohda
11-30-2004, 05:08 AM
Hi Daniel,
This Link will show you the full documentation of how to send SMS using HTTP with clickatell.com
http://www.clickatell.com/downloads/Clickatell_http_2.2.2.pdf
Sending SMS will be same as the code below, but the URL will be changed and more parameters sould be supplied.
Getting Valide Session id also same as the code but the URL will be different.
First at all, you need to register with clickatell.com and then create new API ID after you login.
This API will be used later to get the Valide Session ID which will used in all other commands ( such as SendSMS, PING, getbalance, ... etc )
--------------
This function will return Valide Session ID
----
[quote]
Shared Function ClickatellGetConnected() As String
Try
myHttpWebRequest = CType(WebRequest.Create("http://api.clickatell.com/http/auth?api_id=9191919&user=XXXXX&password=XXXXX"), HttpWebRequest)
' Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
myHttpWebRequest.Method = "GET"
myHttpWebRequest.Timeout = -1
myHttpWebRequest.Proxy = myHttpProxy
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Print the HTML contents of the page to the console.
streamResponse = myHttpWebResponse.GetResponseStream()
Dim streamRead = New StreamReader(streamResponse)
count = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
If Mid(outputData, 1, 2) = "OK" Then
ClickatellGetConnected = Trim(Mid(outputData, InStr("ID:", outputData) + 4, 60))
Else
ClickatellGetConnected = outputData
End If
count = streamRead.Read(readBuff, 0, 256)
End While
' Close the Stream object.
streamResponse.Close()
streamRead.Close()
streamRead = Nothing
' Release the HttpWebResponse Resource.
myHttpWebResponse.Close()
Catch ex As Exception
ClickatellGetConnected = ex.Message
End Try
End Function</CODE>and this one will send SMS
[quote]
Shared Function ClickatellSendNormalSMS(ByVal Session_ID As String, ByVal MsgText As String, ByVal TO_Number As String, ByVal Lang As String, ByVal _From As String) As String
Try
MyURL = ""
If Lang = "EN" Then
MyURL = "http://api.clickatell.com/http/sendmsg?session_id=" & Trim(Session_ID) & "&to=" & TO_Number & "&text=" & MsgText & "&from=" & _From
ElseIf Lang = "AR" Then
MsgText = ConvertUnicodeScreenDataToUCS2MessageData(MsgText)
MyURL = "http://api.clickatell.com/http/sendmsg?session_id=" & Trim(Session_ID) & "&to=" & TO_Number & "&text=" & MsgText & "&unicode=1&from=" & _From
End If
myHttpWebRequest = CType(WebRequest.Create(MyURL), HttpWebRequest)
' If you are behind proxy then put your proxy details below otherwisecomment the 2 lines below
myHttpProxy = New WebProxy("itserver:80", True)
myHttpWebRequest.Proxy = myHttpProxy
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
streamResponse = myHttpWebResponse.GetResponseStream()
Dim streamRead = New StreamReader(streamResponse)
count = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
If Mid(outputData, 1, 3) = "ID:" Then
ClickatellSendNormalSMS = Trim(outputData)
Else
ClickatellSendNormalSMS = Trim(outputData)
End If
count = streamRead.Read(readBuff, 0, 256)
End While
' Close the Stream object.
streamResponse.Close()
streamRead.Close()
streamRead = Nothing
myHttpWebResponse.Close()
Catch ex As Exception
Call DBAddErrorLog(ex.Message, "ClickatellSendNormalSMS")
ClickatellSendNormalSMS = ex.Message
End Try
End Function</CODE>You can find more on the documenation on how to Send Batch SMS up to 300 Numbers Per Request.
Hope this help you.
Good Luck
Mohammed Ali
danielliu8
11-30-2004, 06:26 AM
Thanks a lot, Mohammed Ali
1.
I tried to run your code, error for "readBuff not defined."
Therefore, I added "Dim readBuff(256) As [Char]"
2.
Had a hard time to login to clickatell.com to create API ID, I do not have any Client ID, I only have my userName and password, any suggestion?
thanks a lot.
daniel
mohda
12-01-2004, 04:36 AM
Yes, I forgot the declaration part for variables
[quote]
privateShared myHttpWebRequest As HttpWebRequest
' Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
private Shared myHttpWebResponse As HttpWebResponse
private Shared MyURL As String
' Print the HTML contents of the page to the console.
private Shared streamResponse As Stream
private Shared readBuff(256) As [Char]
private Shared count As Integer</CODE>And regarding the client ID, when you register with Clickatell you'll receive the client id with your user name and password.
Check the email from clickatell when you register with them and you'll find your Client ID.
Once you login at clickatell.com
Go to: Product Control (from left menu)
Select : HTTP/S
and fill the form( give the product name, any name ... etc )
It'll generate an API_ID which you'll use in the code.
danielliu8
12-01-2004, 09:48 AM
Thanks a lot,
I got API-ID, and tried to run your code, but "ConvertUnicodeScreenDataToUCS2MessageData" not declared,
Is it possible for you to post the complete code to send SMS from asp.net?
Thanks again for your help.
daniel
danielliu8
12-02-2004, 04:42 AM
thanks a lot,
I run your code like following:
************************************************** ****
Try
Dim sessionID As String = mobileClass.ClickatellGetConnected
If sessionID <> "" Then
mobileClass.ClickatellSendNormalSMS(sessionID, "test from daniel", "5107598888", "EN", "daniel@27623.com")
End If
Catch ex As Exception
lblError.Text = ex.Message
End Try
****************************************
and get Errorin ClickatellGetConnected function:
"The underlying connection was closed: The proxy name could not be resolved, verify correct proxy configuration."
I think maybe because I did not get valid API_ID?(when I create API_ID, I input our web hoster's IP Address, is this the problem?)
thanks a lot for your help.
daniel
mohda
12-02-2004, 08:25 AM
Ignore ConvertUnicodeScreenDataToUCS2MessageData , because it's for ARABIC and i am using it to convert arabic characters to unicode.
Just ignore it .
Below are two methods, Once to Check your clickatell balance and second to check the delivery for a message .
[quote]
Shared Function ClickatellGetBalance(ByVal Session_ID As String) As String
' Get Balance
Try
MyURL = ""
MyURL = "http://api.clickatell.com/http/getbalance?session_id=" & Trim(Session_ID)
myHttpWebRequest = CType(WebRequest.Create(MyURL), HttpWebRequest)
'myHttpWebRequest.Proxy = proxyObject
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
streamResponse = myHttpWebResponse.GetResponseStream()
Dim streamRead = New StreamReader(streamResponse)
count = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
ClickatellGetBalance = Trim(outputData)
count = streamRead.Read(readBuff, 0, 256)
End While
' Close the Stream object.
streamResponse.Close()
streamRead.Close()
streamRead = Nothing
myHttpWebResponse.Close()
Catch ex As Exception
Call DBAddErrorLog(ex.Message, "ClickatellGetBalance", "")
ClickatellGetBalance = ex.Message
End Try
End Function
Shared Function ClickatellChkDelivery(ByVal Session_ID As String, ByVal Msg_ID As String) As String
' Get Balance
Try
MyURL = ""
MyURL = "http://api.clickatell.com/http/querymsg?session_id=" & Trim(Session_ID) & "&apimsgid=" & Trim(Msg_ID)
myHttpWebRequest = CType(WebRequest.Create(MyURL), HttpWebRequest)
'myHttpWebRequest.Proxy = proxyObject
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
streamResponse = myHttpWebResponse.GetResponseStream()
Dim streamRead = New StreamReader(streamResponse)
count = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
ClickatellChkDelivery = Trim(outputData)
count = streamRead.Read(readBuff, 0, 256)
End While
' Close the Stream object.
streamResponse.Close()
streamRead.Close()
streamRead = Nothing
myHttpWebResponse.Close()
Catch ex As Exception
Call DBAddErrorLog(ex.Message, "ClickatellGetBalance", "")
ClickatellChkDelivery = ex.Message
End Try
End Function</CODE>
mohda
12-02-2004, 09:41 AM
daniel? did you removed the proxy part as i mentioned before ?
Are you behine proxy server or you have direct connection to Internet?
danielliu8
12-02-2004, 10:11 AM
I use our testserver which connect to internet throughour network,
I comment out all the proxy code from both ClickatellGetConnected andClickatellSendNormalSMS functions, now the error is:
ERR: 007, IP Lockdown violation
Is it the API_iD problem?
thanks a lot.
daniel
mohda
12-03-2004, 02:37 AM
You can't do anything if you didn't get the API_ID.
First and before anything you should get API_ID from your account with clickatell.com
And then you need to remove the IP Lock Down from your preference in your HTTP product.
Make it blank.
You only need to give the name for the product in HTTP/S.
I'll ask a qutesion? Do you have the permission to install custom dll componenets on your hosting server?
If yes, then i advice you to install COM Object componenet on server and use the interorp in .NET to use this componenet. It'll be more easy than using the HTTP/S Protocol (httpwebresponse and webrequest).
You can download the Com Object from : http://www.clickatell.com/downloads/COM-API_Installer.exe
And here is the link for documentation for this com object.
http://www.clickatell.com/downloads/Clickatell_com_2.2.1.pdf
But also you need first to create API_ID for COM Object product.
Thanks
danielliu8
12-03-2004, 04:26 AM
I have my API_ID, but I doubt it is a valid, since when I create API_ID, i have to input web server's IP address. But I am testing from my laptop, Is this a problem?
Do not understand how to "remove the IP Lock Down from your preference in your HTTP product. Make it blank.
You only need to give the name for the product in HTTP/S.".
I checked your code, there is no code for IP Lock Down.
ANother thinking is, I am testing in USA, is clickatell.com works in USA? and how many Carrier they covered? I am testingT-Mobile internet phone now.
We can not install any com in our hoster server,
any suggestion to make it works?
thanks great fro your help.
daniel liu
owner
www.diamondbarweb.com (http://www.diamondbarweb.com)
mohda
12-03-2004, 07:36 AM
Hi,
I tried to send an SMS to my friend Mobile In USA but didn't arrive,
But you can check the coverage from the URL below
http://www.clickatell.com/brochure/coverage.php
And about IP LockDown,
Login to CLickatell.com Web Site and thengo to products, and select HTTP/S, in perefernce, remove the IPD address from IP LockDown field.
I think you've entered the IP address when you create the API_ID. Just remove it from the HTTP/S Configuration from Clickatell web site.
danielliu8
12-03-2004, 11:02 AM
I removed lock down, and send again, seems works, no any error message, but my mobile phone did not receive any SMS.
It showes the T-Mobile covered.
something wrong?
thanks a lot.
daniel
mohda
12-05-2004, 06:45 AM
Could you please give me the return string of calling of procedure : ClickatellSendNormalSMS ?
danielliu8
12-08-2004, 07:03 AM
Sorry that I am out of office this week, I will tell the return string of calling of procedure : ClickatellSendNormalSMS next week.
Thanks again, have a nice weekend.
daniel liu
danielliu8
12-10-2004, 10:57 AM
I am back,
Here is the error:
When I call
Dim sessionID As String = mobileClass.ClickatellGetConnected, error occured at
"Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)",
Error message:
"The underlying connection was closed: The remote name could not be resolved."
Seems SessionID problem, it worked fine last week to get SessionID and call mobileClass.ClickatellSendNormalSMS function, but it not working now.
Any suggestion?
(I contacted Clickatell.com, they have no response for the problem.)
Thanks a lot for your help.
daniel liu
mohda
12-11-2004, 11:12 AM
welcome back,
This is proxy problem i think.
Are you behind proxy?
If yes, they i think you put the proxy server in httpproxy, am right?
Could you please post your code.
(In case you put the proxy name such as "myproxy:8080" then you need to add "myproxy" to file services C:\WINDOWS\system32\drivers\etc
Regards
vBulletin® ©Jelsoft Enterprises Ltd.