Here is the architecture of WAPReetings:
Cards.asp > cardDetail.asp > gnerateCard.asp > sendCard.asp
Let's explain step by step how it works:
1 First we browse the cards
2 After browsing we select and see the details of the card.
3 When we are satisfied with the card, we generate it with our own customized greeting text, email address and name of the receiver, and also the sender's name and email.
4 After submitting that data we are directed to the sendCard.asp where the information we submitted into the generateCard.asp is retrieved. Then we send our WAPReeting via CDONTS. The email contains the url of our card. Here is an example URL: http://www.myserver.com/getCard.asp?rid=19121978
Now let's get a picture of the receiver scenario:
ReadMails.asp > getCard.asp
The receiver scenario is very simple:
1 Browse to the page readMails.asp where we can see our WAPReetings.
2 As we read the mail, we get the URL containing the Receiver ID. The link retrieves our WAPReetings.
All the ASP files mentioned in this article can be downloaded here: Use Save Link/Target As on the following links:
common.asp
cardKit.asp
cards.asp
common.asp
defarult.asp
generateCard.asp
getCard.asp
global.asa
login.asp
logproc.asp
generateCard.asp
getCard.asp
global.asa
login.asp
default.asp
wapEnable.asp
send.asp
sendCard.asp
test.asp
testBed.asp
readMails.asp
That's the complete overview of how WAPReetings works. Now let's explore the code.
Our Tools
We utilize Microsoft Active Server Pages (ASP) for server-side scripting and our script language is VBScript. Our output language is Wireless Markup Language (WML), and the database in this example is SQL Server 2000 Beta.
Here is the Database Structure:

Now let's move to the coding, starting with CardKit.asp because it is our main file.
First here are all the functions, then we'll describe them step-by-step:
1- connectMe()
2- getCardList()
3- getCardDetail()
4- sendCard()
5- getWAPReetings()
connectMe() is the simple Connection Object generation function that refers to any variable passed to that function.
Function connectMe(connObj)
Set ConnObj = Server.CreateObject("ADODB.Connection")
strConnection = "PROVIDER=SQLOLEDB.1; Data Source=local; Initial Catalog=wreetings; user id=sa; password=;"
ConnObj.Open strConnection
End Function
The second line uses the variable that we pass as parameter and then makes a connection object from it.
GetCardList()
This function generates the List Box in WML format for the cards available in our database.
Dim strCardList
'Loop through the records... and create the Option Tag
Do while Not cardListRstObj.EOF
strCardList = strCardList & "<option value='" &
cardListRstObj("cardID") & "'>"
strCardList = strCardList & cardListRstObj("cardDescription") &
"</option>"
cardListRstObj.moveNext
Loop
'now encapsulate the Option tag into the Select Tag
strCardlist = "<select name='cardsList'>" & strCardList & "</select>"
getCardList = strCardList
After opening the Recordset we then loop through the Recordset and start generating the Option tags to generate the card list. But at the end we encapsulate our existing option tags string into the select tag, and then we return this string to the function. Voila! We have the following:

Now the question is how to call this function in our file named cards.asp. The following is from the cards.asp file:
<!--#include file="wapEnable.asp"-->
<!--#include file="cardKit.asp"-->
<%
Dim ConnObj
Call connectMe(connObj)
%>
<wml>
<card id="cardsList" title="Available Cards">
<p>
<b>Select your Card</b>
<%Response.write getCardList(connObj)%>
<do type="accept" label="Detail">
<go href="cardDetail.asp" method="post">
<postfield name="cardID" value="$(cardsList)"/>
</go>
</do>
</p>
</card>
</wml>
To start with we declare a local variable and then pass it to our connectMe(connObj).
When we call our getCardList(connObj) function, by providing the connection object variable, we don't need any other Connection Object.
GetCardDetail()
When the user selects a card from the card list, we take them to cardDetail.asp, which uses the getCardDetail() function. This function has two parameters: CardID and ConnObj.
The following is from getCardDetail().
strSQL = "SELECT * from tblCards"
strSQL = strSQL & " WHERE cardID = " & cardID
detailRstObj.Open strSQL, connObj,adOpenStatic
'Is Data is available?
If detailRstObj.EOF = false Then
'If so, then we will generate the text, to display the card detail.
returnString = "<b>Detail:</b> " & detailRstObj("cardDescription") & "<br/>"
returnString = returnString & "<b>Image:</b> <img src='." & detailRstObj("cardLoc") & "'"
returnString = returnString & " alt='" & detailRstObj("cardDescription") & "'/>"
End If
'Return the generate string...
getCardDetail = returnString
First we generate the SQL to find the card the user has chosen. Then we check whether the selected card data is available in our database. If it is, then we generate the string containing the WML tags, such as <b> and <img>. There are two attributes to the <img> tag; Src and Alt. Both attributes are required. We paste our description from the database in the Alt tag, and the image location will go in the Src attribute.
Here's the result (an aside: Eid is an Islamic holy day).

Here is an excerpt from cardDetail.asp.
<p>
<%Response.write getCardDetail(varCardID, connObj)%>
<do type="accept" label="Confirm">
<go href="generateCard.asp?cardid=<%=varCardID%>"/>
</do>
</p>
We are returning the String from getCardDetail() and using it as we did in getCards().
The line starting with the <go> tag requires close attention. In the go tag there is an attribute named href, which is close to the action attribute in the form tag. With the action attribute you define the file name and where you want to submit the file, and the same applies to the WML Go tag. We refer to generateCard.asp, but by passing the QueryString variable named cardID (note this is the URL String Variable) and instead of using the Post Field technique, we can also pass our values using the URL String Variables.
Before we proceed to the next function, let's look at generateCard.asp.
GenerateCard.asp: This is a form that takes Sender Name, Sender Email, Receiver Name, Receiver Email and Greeting Text. It then submits it to sendCard.asp.
sendCard()
Here is the list of parameters for this function:
1- CardID = CardID
2- SName = Sender Name
3- SEmal = Sender Email
4- RName = Receiver Name
5- REmail = Receiver Email
6- Gtext = Greeting Text
7- ConnObj = Connection Object Reference
So this function is bit lengthy in parameters. We pass Card ID which the user has chosen from cards.asp. Sender Name, Sender Email, Receiver Name, Receiver Email and Greeting Text come from generateCard.asp and are submitted to the sendCard.asp file.
Here's another code snippet:
deliverRstObj.Open "tblCardsToDeliver", connObj, adOpenKeyset,adLockOptimistic, adCmdTable
deliverRstObj.AddNew
deliverRstObj("cardID") = Cint(lCardID)
deliverRstObj("sName") = lSName
deliverRstObj("sEmail") = lSEmail
deliverRstObj("rName") = lRName
deliverRstObj("rEmail") = lREmail
deliverRstObj("greetingText") = lGText
deliverRstObj.Update
deliverRstObj.Close
'Fetch the last Identity Value and paste it into the receiverID
deliverRstObj.Open "SELECT @@IDENTITY",connObj,adOpenStatic,adLockReadOnly
receiverID = deliverRstObj.Fields.Item(0)
deliverRstObj.Close
'Create the URL, for this v will retrieve the ReceiverID which is
'an Identity Field, and after updating it, we retrieve it and
'concatenate with URL String
varURL = "http://localhost/wapreetings/getCard.asp?rid=" & receiverID
'Subject Line String
varSubject = "You've got WAPReetings"
'Handling Error
if Err.number <> 0 Then
sendCard = Err.number & "-" & Err.Description & "-" & Err.Source
Exit Function
Else
SendCard=true
End If
'Generate the Body Text String which create the body text.
varBody = varBody & chr(13) & "Please pick your WAPReetings from: " & chr(13) & chr(13)
varBody = varBody & "<a href='" & varURL & "'>" & varURL & "</a>" & chr(13)& chr(13)
varBody = varBody & "Regards, " & chr(13)
varBody = varBody & "WAPReetings Staff"
'Sending mail...
Dim cdontsMailObj
Set cdontsMailObj = Server.CreateObject("CDONTS.NewMail")
cdontsMailObj.From = lSEmail
cdontsMailObj.To = lREmail
cdontsMailObj.Subject = varSubject
cdontsMailObj.Body = varBody
cdontsMailObj.Send
We use the AddNew method of the Recordset Object to add the data into the database. You can use Insert Query as well.
Then we want to get the currently appended record's auto generated identity. By sending the "SELECT @@IDENTITY" we now have a Receiver ID which helps us to generate the URL we are going to send in the Email. And then we generate the string for Subject & Body and also append the URL that we generated after adding our record.
We use CDONTS to send the Email using our local server, namely its properties such as From, To, Subject and Body from the created CDONTS Object.
From = Sender Email, in our case the value is lSEmail variable
To = Receiver Email address, in our case the lREmail variable
Subject = Subject Line, the varSubject variable.
Body = Body Text, varBody with concatenated varURL.
The sendCard() function returns two alternatives. For success it returns True, and if an error occur it returns the error description and number.
In sendCard.asp that's how the sendCard() function is implemented:
<%
On Error Resume Next
call ConnectMe(connObj)
'Get the variable from the generateCard.asp
varSenderName = Request.form("sName")
varSenderEmail = Request.form("sEmail")
varReceiverName = Request.form("rName")
varReceiverEmail = Request.form("rEmail")
varGreetingText = Request.form("gText")
varCardID = Request("cardID")
strStatus = sendCard( varCardID, varSenderName, varSenderEmail, varReceiverName, varReceiverEmail, varGreetingText, connObj)
Dim message
If strStatus = true then
message = message & "<p align='center'><strong>WAPReetings. </strong></p>"
message = message & "<p><br/>WAPReeting Successfully deliver...</p>"
Else
message = "<p>" & strStatus & "</p>"
End If
%>
<wml>
<card id="sendCard" title="Card Send Status">
<%
Response.Write message
%>
<do type="accept" label="Home">
<go href="cards.asp"/>
</do>
</card>
</wml>
The first lines of code get values from generateCard.asp using Request.Form.
After this we pass our information to sendCard(). If the code works fine it will return True, which indicates that the email was sent. In this case the message variable will hold a message which says "WAPReetings Successfully delivered
". Otherwise it will display the Error Description and Error Number.
Now we'll learn how to read our WAPReetings
getWAPReetings()
Here comes the code.
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 (Receiver ID). This is the same as we generated and posted into the database and emailed to the user.
First we generate the SQL to get the information regarding Receiver ID. Then we check if the data exists. If it does, then we generate an Array with 4 Elements, which will be used in getCard.asp:
0 = SenderName
1 = Greeting Text
2 = Card Description / Title
3 = Card Location
Here's more code.
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%>
We receive the URL String Variable using the Request.QueryString method. We then pass this value to the getWAPReetings() function, which gets the value for Receiver ID. And if data is available it will return the array and we then paste this Array into our text as we did before with the MessageText variable.
There our story ends, but there is one little thing to add - how to read the emails on a WAP-enabled device. It is pretty simple in normal HTTP using the ASP / HTML combination and CDONTS.
Here's the code. It uses the local SMTP Mail Server, but if you want to make your code read the remote emails then you may prefer ASPMail and ASPPop3 from serverobjects.com. You can download the evaluation versions and test your code.
<%
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
%>
Conclusion
The application is very simple and can easily be extended, but remember WAP devices are not capable of downloading data faster than 14,400 bytes. When you have more than four or five cards, which professional applications have, you have to follow the pagination rule. You show the minimal amount of data on the page, and remember that some WAP mobile phones don't accept images, which puts our application in dark.
You can easily incorporate ASPMail for reading your email and ASPPop3 for sending your mail through WAP enabled devices using ASP.