GetCard.asp: getWAPReetings()
We will first explore this function and then we will see that how
to implement in our ASP Pages.
So here are the code snippets:
Dim wapreetingDetail(3)
strSQL = "SELECT tblCards.*, tblCardsToDeliver.* From tblCards, tblCardsToDeliver "
strSQL = strSQL & "WHERE tblCards.cardID = tblCardsToDeliver.cardID "
strSQL = strSQL & "AND tblCardsToDeliver.receiverID = " & rid
Set wapreetingRstObj = Server.CreateObject("ADODB.Recordset")
wapreetingRstObj.Open strSQL, wapreetingsConnObj, adOpenStatic,adLockReadOnly, adCmdText
'Return the array contain the following indexes....
'SenderName = 0
'GreetingText = 1
'CardDescription = 2
'CardLocation = 3
If Not wapreetingRstObj.EOF = False THen
wapreetingDetail(0) = wapreetingRstObj("sName")
wapreetingDetail(1) = wapreetingRstObj("greetingText")
wapreetingDetail(2) = wapreetingRstObj("cardDescription")
wapreetingDetail(3) = wapreetingRstObj("cardLoc")
getWAPReetings = wapreetingDetail
Else
getWAPReetings = "Error"
End IF
GetWAPReetings has a parameter, RID, namely Receiver ID, this is
the same as we generated and posted into the database and emailed it
to the user.
First we will generate the SQL to get the information regarding
with the Receiver ID.
Then we will check is the data exists. If it is then we will
generate an Array with 4 Elements:
0 = SenderName
1 = Greeting Text
2 = Card Description / Title
3 = Card Location
It will be used in the getCard.asp, but how can you reach this
page, we will discuss this after this code snippet brief.
varRID=Request.QueryString("rid")
Dim wapreetingArray
wapreetingArray = getWAPReetings(varRID)
If isArray(wapreetingArray) Then
'SenderName = 0
'GreetingText = 1
'CardDescription = 2
'CardLocation = 3
messageText = "Sender: " & wapreetingArray(0) & "<br/>"
messageText = messageText & "Greeting Text: " & wapreetingArray(1) & "<br/>"
messageText = messageText & "Caption: " & wapreetingArray(2) & "<br/>"
messageText = messageText & "Card: <img src='" & wapreetingArray(3) &"' alt='" & _
wapreetingArray(2) & "'/>" & "<br/>"
Else
messageText = "No WAPReeting"
End If
%>
<wml>
<card id="myCard" label="My WAPReetings">
<p>
<%=messageText%>
When we receive the URL string variable using Request.QueryString.
We will then pass this value to the getWAPReetings() function
which will get the value regarding with Receiver ID. And if data is
available it will return the array and then we will paste this Array
into our text as you seen in the above code snippet with the
MessageText variable to generate content to be displayed.
Our story ends, but there is one little thing I have to discuss,
how to read the emails on WAP Enable Device. It is pretty
simple as you did in normal HTTP using ASP / HTML / WML
Combinations. We return WML XML in the actual email and the use
CDONTS to send the email.
The following code snippets will explain how to do it. But
remember it uses the local SMTP Mail Server, but if you want to make
your code read the remote emails then I will prefer ASPMail &
ASPPop3 from
http://www.serverobjects.com. You can download the
evaluation version. I have already tried it, and found them
superb components to access your remote emails.
ReadMails.asp
<%
On Error Resume Next
' set up email address of sender we are interested in
Dim varSubject
varSubject = "You've Got WapReetings"
' get to collection of messages
Dim objSession
Set objSession = CreateObject("CDONTS.Session")
'Retrive from my local mail server.
objSession.LogonSMTP "Mohammed Mudassir", "mmudassir@myserver.com"
Dim objInbox
Set objInbox = objSession.Inbox
Dim colMessages
Set colMessages = objInbox.Messages
' count how many messages come from this sender
Dim i
Dim nMessages
wapMsgs = 0
For i=1 To colMessages.count
'Using InStr we will check either the subject in which we are interested
exists?
subjectStatus = Instr(1, colMessages(i).Text, varSubject, vbTextCompare)
If subjectStatus > 0 Then wapMsgs = wapMsgs + 1
Next
' write main index card
Response.Write "<card id=" & Chr(34) & "index" & Chr(34) & _
" title=" & Chr(34) & "Inbox" & sChr(34) & ">" & vbCrLf
Response.Write "<p>" & wapMsgs & " Messages</p>" & vbCrLf
For i=1 To colMessages.count
subjectStatus = Instr(1, colMessages(i).Text, varSubject, vbTextCompare)
If subjectStatus > 0 Then
Response.Write "<p><a href=" & Chr(34) & "#mail" & CStr(i) & _
Chr(34)& ">" & _
colMessages(i).Subject & "</a></p>" & vbCrLf
End If
Next
Response.Write "</card>" & vbCrLf
' write cards with the messages on
For i=1 To colMessages.count
subjectStatus = Instr(1, colMessages(i).Text, varSubject, vbTextCompare)
If subjectStatus > 0 Then
Response.Write "<card id=" & Chr(34) & "mail" & CStr(i)& Chr(34) & _
" title=" & Chr(34) & "Message Text" & Chr(34) & ">" & vbCrLf
Response.Write "<p><b>" & colMessages(i).Subject & "</b></p>" & vbCrLf
Response.Write "<p>" & colMessages(i).Text & "</p>" & vbCrLf
Response.Write "<p><a href=" & Chr(34) & "#index" & Chr(34)& ">" & _
"Index</a></p>" & vbCrLf
Response.Write "</card>" & vbCrLf
End If
Next
' clean up etc.
objSession.Logoff
Set objSession = Nothing
%>
Now this is bit dirty code, but I included some inline code, so
you can easily understand what is going on.
Conclusion:
The application is very simple and can easily be extendable, but
remember WAP Device are not capable to get the data more than 14400
bytes. When you have more than 4 or 5 cards which professional
application have so you have to follow the pagination rule, you show
the the minimal amount of data on the page, and also remember that
some WAP Mobile Phones don't accept Images, and this put our
application soul in dark.
About Email you can easily incorporate ASPMail for reading your
email and ASPPop3 for sending your mail through the WAP Enable
devices using ASP very easily.
Mohammed Mudassir comes from Karachi, Pakistan and currently
working in a multi-national web development firm as an ASP Developer,
with primary responsibility for developing ASP related projects. In
leisure time he does research on technologies like VML, XML, WAP,
ADO, COM+, VoiceXML - the list goes on and on. He also like to
read business related Information Technology issues, but when he have
nothing to do, he enjoy Music & Movies, especially cartoons. You
can reach Mudassir at
mmudassir@cyber.net.pk....