Sending Digital PostCards with ASP and the free component ASPEmail from Persits software.

Thursday Apr 22nd 1999 by ServerWatch Staff

This code is a little bit longer, so try to not get lost. Of course I am sending an ZIP with the component I use.

Joco Vieira

This code is a little bit longer, so try to not get lost. Of course I am sending an ZIP with the component I use.

1. First you must create an DataBase (I use a DataBase to put the PostCards information so that when a
person gets the mail with the post card only have to click on the link and the page apears, goin to DB to
get the Data.

So here it is the structure of my DataBase (you can make your own, with more information if you intend to.

Postal(ID_POSTAL As Autonumber, passw As integer, postal As Text,nameto As Text, namefrom As Text,
emailfrom As Text, emailto As Text, Message As Text, Data As Text)

(ex: table(field1 As type, field2 As type) )

2. Then I had to have the images of the PostCards, all you have to do is to have 6 postcards images,
in a Small size, and the size you want when a person goes to see the Post Card. Also the images for
the buttons ( I use a lot of images for the buttons, but the main are the button to View, to Send, to Repeat ).

3. Now comes the code, well I am not going too much deep at the stuff about HTML, i will only concern
at the ASP. any doubt just e-mail me. But you will have to make an HTML form, where I used the
POST method 'cause I don't like to see all the information submited at the Address link box.

FILE: makin.html

This is the file where we have the form that gets all the info we need to make the Digital Post Card

<form name="postalsent" method="post" action="view.asp?fromn=seeit" target="_self">

       <td width="24" valign="bottom"><font face="Arial">
                  <input type="radio" value="postal1" name ="R1">
                <td width="140"><font face="Arial"><IMG border=2 height=86 src="images/postal1.gif"

                <td width="12" valign="bottom"><font face="Arial">
                  <input type="radio" value="postal2" name ="R1">
                <td width="151"><font face="Arial"><IMG border=2 height=87 src="images/postal2.gif"

                <td width="24" valign="bottom"><font face="Arial">
                  <input type="radio" value="postal3" name ="R1">
                <td width="140"><font face="Arial"><IMG border=2 height=88 src="images/postal3.gif"

                <td width="12" valign="bottom"><font face="Arial">
                  <input type="radio" value="postal4" name ="R1">

                    <INPUT name="nameto" size=18 style="LEFT: 1px; TOP: 2px">
                    <input name="emailto" size="18" >
                    <input name="namefrom" size="18" >
                    <input name="emailfrom" size="18">
                    <TEXTAREA cols=18 name=message rows=2></TEXTAREA>
                          <input type="image" name="bseeit" src="images/seesentbotton.gif"
 border =0 height=51 width=110>
                      <td width="32%"><a href="makin.htm"><img border=0 height=53 
src="images/resetbotton.gif" width=41></a></td>
As you see in this example I use an image for Submit Button, and another 
image for reset button, at the reset button I made an reload of the page
(refresh) that really cleans all the fields.
At action="view.asp?fromn=seeit" I use fromn to know if the access to the 
view.asp is from within the creation fase or from the person that clicked
at the e-mail link .'Seeit' to those that are creating and 'out' to those 
that are going to see a sent Digital Card.
Well at this time (in the file makin.html) all we want to do is to send
the information. The fields that i'm using are the ones named above;R1,
nameto, mailto, namefrom, emailfrom.
FILE: view.asp
this the the important part, here we will see if there is a person 
previewing the future Card, or a person seeing a sent card.
 We will take all the information sent by the POST form of the 
previous file.
         Dim fromn 
         Dim ident
         Dim psw
         Dim erring ' this is the one that will make the validation
         ' if the Card exists or not 
         erring = 0 ' ok, by definition the card exists
         ' i normaly use 0 and 1 for boolean, 'cause it is quicker
         fromn = Request.QueryString("fromn") ' takin the information
         'from the link that leaded to this file, this one tell us
         'what kind of access is being taken
         ident = Request.QueryString("ident") ' here we take the ID
         ' from the post card, for us to know wich card we want to see
         ' all this information will be compared with the one in the datadase
         ' we will see how the Data is being submited to the DB later
         psw = Request.QueryString("psw") ' this is the password
         ' we do not want that a person that nows that exists a postal with
 	 ' the ID 13 tries to see a one with ID 12... we will generate
         ' a random number, that i use to psw, that it is a kind of password
         ' and when we make a search the ID must be right as also the psw
        if fromn="seeit" then ' if we just want to see the preview
         ' i have created sessions to keep the information, so that I can
         ' be at ease to take control of all my steps.         
         session("postal") = Request.form("R1")
         session("namefrom") = Request.form("namefrom")
         session("emailfrom") = Request.form("emailfrom")
         session("nameto") = Request.form("nameto")
         session("emailto") = Request.form("emailto")
         session("message") = Request.form("message")
        else ' if not thats because there is someone that wants
             ' to see a card already sent
         Set Conn = Server.CreateObject("ADODB.Connection") ' we open the DB 
         ' connection"DSN=postal;" ' the DSN you made at the ODBC for the DB
         Set rs = Server.CreateObject("ADODB.Recordset") ' create the recordset
         SQLStmt = "SELECT * FROM postal WHERE ID_POSTAL = " & CInt(ident) & " AND passw = " & CInt(psw)
         ' this is asimple SQL statement that see if the ID and password are connected in the DB
         rs.Open SQLstmt,Conn,1,2 ' we execute the SQL statement
         if rs.EOF then 
            erring = 1 ' if it goes to the end thats because it doesn't exists
           else ' but if exists we take all the information in the DB to put it at the page
            session("postal") = rs("postal")
            session("namefrom") = rs("namefrom")
            session("emailfrom") = rs("emailfrom")
            session("nameto") = rs("nameto")
            session("emailto") = rs("emailto")
            session("message") = rs("message")
         end if
      end if
     <body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" 
background="images/something.gif" bgcolor="#002400" text="#FCC403">
' at this time we will see if there is no error and if the fromn have the validated information,
' and make shure that there is an Digital Post Card choosen by ratio buttons
if erring <> 1 and (fromn="seeit" or fromn="out") and session("postal")<>"" then   
' if everything is correct we show the information
' well, you can put the information at the way you want, you don't need to make like this
<div align="left">
 <table border="0" width="580" cellspacing="0" cellpadding="0">
    <td width="50%" valign="top" align="left"><br>
    <img src="images/<%=session("postal")%>.jpg" hspace="5" border="2" WIDTH="354" HEIGHT="231"></td>
    <td width="50%"><table border="0" cellspacing="3" width="100%" cellpadding="3"
    bordercolor="#000000" height="202">
        <td width="100%" height="109"><p align="left"><font face="Arial"><br>
                <small>From:</small> <strong><%=session("namefrom")%></strong><br>
                <small>Email:</small><small><strong> <%=session("emailfrom")%></strong></small><br>
                <small>To:</small><strong><small> <%=session("nameto")%></small></strong><br>
                <small>Email:</small><small><strong> <%=session("emailto")%></strong></small></font>
            <td width="100%"><font face="Arial"><small>Menssage:</small><br>
              <font size="2"><strong><%=session("message")%></strong> </font></font></td>
            <td width="100%" align="center" valign="middle" height="29"> 
            <%if fromn="seeit" then 'if fromn have "seeit we will show the buttons "to send" and "to retry"%> 
              <p align="left"><br>
        <a href="javascript:history.back()"><img src="images/rebuildbotton.gif" width="60"
        height="53" border="0"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a
        href="enviado.asp"><img src="images/sendbotton.gif" width="41"
        height="53" border="0"></a> </td>
              <%else ' if not, thats because its someone viewing a made Card, so we will show a reply button%> 
      <a href="makin.htm" target="_self" ><img border="0" height="72" src="images/replybotton.gif"
<%end if 
  else ' this eles is if there isn't no Card validated, we will show the error image
%> <br><br><center>
<img src="images/error.gif" width="322" height="53" border="0"></a></center><br>
end if
' this is where i remove all the postcards in the DB with more than 30 days
' i do not want to make a huge DB, so I clean it just to have the messages of the last 30 days
' you can now ask.. "-So, why did you put this code here?" so my response is:
' "- Because this is the place where you fill the DB, so if you are going to put another record
' at the DB, lets clean some old stuff."
     d = now() ' here we will get the system date (yes, the server date)
     d = d - 30 ' we will decrease 30 days at the date we have
     Set Conn = Server.CreateObject("ADODB.Connection") ' make the connection to the ActiveX Database Object"DSN=postal;"      ' Open the DSN we have been using
     Set rs = Server.CreateObject("ADODB.Recordset") ' set the recordset
     SQLStmt = "DELETE FROM postal WHERE data < #" & d & "#" ' make the SQL statement that delete
     ' all the entrys with a date minor than the todays date minus 30 days
     rs.Open SQLstmt,Conn,1,2 ' execute the SQL statement
FILE: enviado.asp
At this time, we will validate all the information that it is supposed to send as well the data that we will
put in the DB. If everything is well we make the data in DB and we will send the information to
the receiver by e-mail. I will explain later how to get the free e-mail component, how to register it at the server
and how to use it
   Dim identifier ' this is the variable that I use to the ID of the post card
   Dim goby ' goby is another made by me kind of boolean to see if the data is ok
   goby = 1 ' lets start it with True
<body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" background="images/something.gif"
 bgcolor="#002400" text="#FCC403">
<font face="Arial"><small><strong>
  if len(session("nameto")) < 2 then ' lets validate the name, I thinks that there is no name with less than 2 letters
' but you can choose your own validation
     goby = 0 ' so if there is any problem there will be an error, so lets change goby, so we know it at the end of the script
  end if
  if len(session("namefrom")) < 2 then ' do it with the name from
  end if
  If Len(session("emailfrom")) <= 5 Then ' validate the e-mail, I have made an arthicle about this, take a look at it
	  If InStr(1, session("emailfrom"), "@", 1) < 2 Then
	     goby = 0
		   If InStr(1,session("emailfrom"), ".", 1) < 4 Then
	         goby = 0
		   End If
	   End If
	End If
  If Len(session("emailto")) <= 5 Then
     goby = 0
	  If InStr(1, session("emailto"), "@", 1) < 2 Then
         goby = 0
		   If InStr(1,session("emailto"), ".", 1) < 4 Then
	         goby = 0
		   End If
	   End If
	End If
if len(session("message")) >= 500 Then ' well, i think that a message with more than 5000 characters is not valid
     goby = 0
  end if  
  if goby = 0 then ' if there is errors lets tell that there is errors , and the data must be corrected
  %><br><br><br><br><br><center><img src="images/error.gif" width="322" height="53" border="0"></a>
  end if
  if goby = 1 then ' but if there is no errorlets put the data in the DB, and send the link to the receiver by e-mail
     Set Conn = Server.CreateObject("ADODB.Connection") '....... no comments see above"DSN=postal;"
     Set rs = Server.CreateObject("ADODB.Recordset") 
     SQLStmt = "SELECT * FROM postal" ' lets select everything from the table postal
     rs.Open SQLstmt,Conn,1,2
     rs.MoveLast ' move the recordset to the end
     identifier = rs("ID_POSTAL") 'take the last ID of the DataBase
     rs.AddNew ' increments a new record
     rs("ID_POSTAL") = identifier + 1 ' put the new number
     randomize() ' use randomize to make a random number
     passw = Int((9999-1)*Rnd + 1) ' take a random number, so that the people can only access to the postal that was sent to them
     rs("passw") = passw ' keep this random at the DB
     identifier = identifier + 1' increment the identifier, the one that tooked the last ID from the DB
     rs("postal") = session("postal") ' put now all the validated information in the DB
     rs("nameto") = session("nameto") ' yes you can do the SQLstmt INSERT, but I think this way is easy to understand
     rs("namefrom") = session("namefrom")
     rs("emailfrom") = session("emailfrom")
     rs("emailto") = session("emailto")
     rs("message") = session("message")
     rs("data") = now ' put the server DateTime, so that you can later see if the informaiton have more than 30 days
     rs.Update ' update it
     rs.Close   ' close the recordset the information is in the DB
    ' now you will see how to use the Persits Free E-Mail component
     Set Mail = Server.CreateObject("Persits.MailSender") ' Create the Mail object
     Mail.Host = "" ' put the mail server you are using
     Mail.From = session("emailfrom") ' send the information of the person that is sending the e-mail
     Mail.FromName = session("namefrom") ' the name too
     Mail.AddAddress session("emailto"), session("nameto") ' Put the e-mail to send to, as well the name of the person
     Mail.Subject = "Digital PostCard to " & session("nameto") '  Create the subject of the message to send
    all the lines now are the message that the receiver will see, so he can go to the page where the Postal with appear
     enviar = "Let me inform you that " & session("namefrom") & Chr(13) & Chr(10) 
     enviar = enviar & "have sent you a digital card. To see it follow the link :" 
     enviar = enviar & Chr(13) & Chr(10) & Chr(13) & Chr(10)
     ' as you can see now after the view.asp i put the fromn as 'out' the ident(ID) as the temporary identifier variable
    ' I created, as well the password....
     enviar = enviar & "http://www.???????.com/view.asp?fromn=out&" & "ident=" & identifier 
     enviar = enviar & "&psw=" & passw & " " & Chr(13) & Chr(10) 
     enviar = enviar & " your card is available till the day " & formatDateTime(d,2) 
     enviar = enviar & Chr(13) & Chr(10) & Chr(13) & Chr(10) & Chr(13) & Chr(10)
     enviar = enviar & "                                                                                 Thanks" 
     Mail.Body = enviar
     On Error resume Next ' sometimes i do not like to bother too much about some stupid errors
     Mail.Send ' here is the command that send the e-mail
     If Err <>0 Then ' if there is any error with the sending a image error message will appear
         %><img src="images/error.gif" width="322" height="53" border="0"></a><%
         ' If you want you can use the code after to see what kind of error appears, i took it
           ' only for good visual effect only
    'Response.Write "<br><br>" & "Error found : " & Err.description & "<br><br>"
         Response.Write "<center><p>SERVER SIDE ERROR, contact site webmaster.</p></center>"
         goby = 0 ' so as an error, goby must be aware of it...
          Response.Write "<br><br><br><center><p>POSTCARD WAS SENT WITH NO PROBLEMS...<br>"    
     End if
end if
' I think that you have seen that I use the JavaScript history.back and go, I use it so when the user come back he don't
' loose any information that was correct
<center><a href="javascript:history.go('-2')"><img src="../images/rebuiltbutton.gif" width="60" height="53"
4.Get the E-Mail free component here I hope you know how to use winzip. So let me explain 
how to setup it.
Put the component wherever you want, I usually put the components I use in a directory at
than register it (after you put it in the directory you want)
'C:\Inetpub\components\regsvr32 AspEmail.dll'
thats all, it is now available (remember the e-mail code only works after you register the component)

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved