asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Centralize Intranet Feedback Using CDONTS
By John DiGiovanni
Rating: 3.5 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    You have a problem where you are responsible for an Intranet site that has several hundred Web sites and each of these Web sites has different owners who maintain the content. You need to implement a way to collect feedback from users who are browsing around these different Web sites and then have this information sent to the owner of the Web in question.

    The easy way to solve this problem would be to have the Web site owners use a mailto HTML link on each page pointing to their own e-mail address. The mailto links will not work properly in environments where not everyone has an e-mail client installed or where there might be public access machines that only have a web browser installed. Also, when a mailto link is used, you cannot gather specific information from the user, they need to know what information to enter. Assuming the mailto link is not an option (which in my case it was not an option) what do you do?

    Enter ASP and CDONTS

    One of my favorite features for IIS 4 is the SMTP service and a COM object that allows a programmer to send an e-mail message with just a few lines of ASP code. This SMTP service, along with a couple of ASP pages and a lookup text file, was my solution to the above problem.

    I have created a few ASP pages that allow the programmer to gather information from the user and then send this information as an e-mail to the person who is responsible for the specific web.

    There are 3 files that make up this little feedback application. They are as follows:

    • feedback.asp - The Web Form that is filled out by the user submitting feedback
    • mailfeedback.asp - The ASP page that assembles the e-mail message and sends it to its destination.
    • maillookup.txt. - This is a text file that contains the web names and e-mail addresses that are going to use the feedback application.
    Along with these files, there needs to be a hyperlink on the pages where you would like the end user to click to give feedback. All of these hyperlinks will be unique in that they will pass along the name of the web to the feedback.asp file. As an example take a look at the following URL.

    http://yoursite.com/feedback.asp?web=marketing

    By creating a hyperlink with the above URL you are pointing the user to the feedback.asp page and passing along a variable called web, which in this case tell feedback.asp that it is the marketing web. The code in feedback.asp uses the Request.QueryString("web") statement to read the information that is passed in this variable.

    Next feedback.asp opens the maillookup.txt file to find a line of text that begins with marketing, since that was the web name that was passed to the feedback.asp file. If the line is found, then feedback.asp uses this information as the destination when sending the e-mail message. Multiple e-mail addresses can be used by separating them with a semicolon. If the web name is not found, then you can have the feedback go to a special e-mail address or to the address of the webmaster or server administrator. This is defined in the mailfeedback.asp file.

    Below is the code from feedback.asp

    
    <%
    Response.Expires = 0
    %>
    
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <html>
    
    <head>
    <body background="ccbackd.jpg">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title> IS Feedback </title>
    <table border="0" width="924" cellpadding="0" cellspacing="0">
    
    </head>
    
    <body text="#000000" link="#008000" vlink="#408080" alink="#FF0000">
    
    <p> </p>
    
    <%
     
    ' Get the mail info from the URL line using request.querystring
    ' And get the referring URL by reading the HTTP_REFERER variable from the server.
    
    strReferingURL = Request.ServerVariables("HTTP_REFERER")
    strWebInfo = Request.QueryString("web")
    strWebInfo = lcase(strWebInfo)
    
    if strWebInfo = "" then
    	strWebInfo = "nothing"
    End If
    
    
    On Error Resume Next
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strFileName = "c:\inetpub\wwwroot\feedbackLookup\maillookup.txt"
    set objFile = objFSO.OpenTextFile(strFileName)
    
    Select Case Err.Number
    	Case 0
    		
    	Do While Not objFile.AtEndOfStream
    		strLine = objFile.ReadLine
    		
    			If lcase(left(strLine,len(strWebInfo))) = strWebInfo then
    				intPos = InStr(strLine, "=")
    				' Read after the = sign to the end of the line.
    				strMailTo = mid(strLine,intPos+1,len(strLine))
    			End If
    	Loop
    	
    	' Close the file
    	objFile.Close
    		
    	
    	Case 50,53
    	 	' Can not read the file.  Send the feedback to the administrator	 
    		strMailTo = "webmaster@yoursite.com"
    
    End Select
    set objFSO = Nothing
    set objFile = Nothing
    
    %>
    <tr>
        <td width="95"></td>
        <td width="817"><font color="#008080" size="6"><p align="center">Welcome to the Inet
        Feedback Web Page</font></td>
    </tr>
    
    <tr>
        <td width="95"></td>
        <td width="817"><font color="#008080" size="4"><p align="center">Please fill out the appropriate information and click
        the button below.</p></font>
        <p align="left"> </p>
    
    <form action="mailfeedback.asp" method="POST">
        
        <p><font color="#008080" size="3">Your Name:</font><input type="text" size="20" name="submitter_name"> </p>
        <p><font color="#008080" size="3">Your Title:</font><input type="text" size="20" name="submitter_title"> </p>
        <p><font color="#008080" size="3">Your Location:</font><input type="text" size="20" name="submitter_location"> </p>
        <p><font color="#008080" size="3">Please enter your feedback in the box below. Thank You.</font></p>
    	<p><textarea name="text_feedback" rows="4" cols="51"></textarea></p>
        
        <input type="hidden" name="mailto" value="<%= strMailTo%>">
        <input type="hidden" name="strReferingURL" value="<%= strReferingURL%>">
        
    	<p><input type="submit" name="Submit" value="Send your Feedback"> </p>
    
    </form>
    <p> </p>
        <p> </p>
    </tr>
    
    </table>
    </body>
    </html>
    
    

    The ASP file first sets Respone.Expires = 0 so that the browser will not cache the page. The next section of ASP will set some variables. The first variable is HTTP_REFERER, which is a server side variable that contains the page that called this ASP page. Then Response.QueryString is used to read the web variable that was passed on the URL line. This web name is used when reading the maillookup.txt file.

    The strFileName variable is used to define the full path and filename of the maillookup.txt file, so this needs to be changed to your specific path and directory. If there is an error reading the file (i.e., not found, etc) then the case 50,53 is used to set the mailto variable to the destination of the webmaster or an administrator so the feedback can go to some destination. The format of the maillookup.txt file is listed below.

    Hr=jdoe@yoursite.com Sales=don.sales@yoursite.com;jane.doe@yoursite.com Marketing=youraddress@yoursite.com WebMaster=webmaster@yourcompany.com

    This file can be created with any text editor such as notepad and should contain each web that you want to use feedback on along with the e-mail address of the person who is responsible for the web. Each entry has to be on its own line with the webname=e-mail address format. Also be aware that when reading the text file the information is case sensitive.

    After the ASP code you will see standard HTML code that is used to display the form that the user fills out. Fields can easily be added or deleted from this section of code. It this example I am asking for Name, Title, Location and Comments. This can certainly be customized to fit specific needs.

    Standard HTML input tags are used for the input. The mailto information and the referring URL are passed to the mailfeedback.asp file by using hidden input tags. This is one way to pass data from one page to another. Since we are using ASP, session variables can also be used.

    After the user clicks the submit button the mailfeedback.asp page is executed. This page will read all of the text boxes that were on the HTML form including the mailto and referring URL information that are in hidden fields. This information is assembled in an e-mail message and sent to the destination address that was specified in the maillookup.txt file.

    Here is the mailfeedback.asp code

    
    <%
    Response.Expires = 0
    If Request.Form("text_feedback") = "" then
    	Response.redirect "feedback.asp"
    End If
    %>
    
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <html>
    
    <head>
    <body background="ccbackd.jpg">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title> IS Feedback </title>
    <table border="0" width="924" cellpadding="0" cellspacing="0">
    
    </head>
    
    <body text="#000000" link="#008000" vlink="#408080" alink="#FF0000">
    
    <p> </p>
    
    
    <%
    	useragent = Request.ServerVariables("HTTP_USER_AGENT")
    	ipaddress = Request.ServerVariables("REMOTE_ADDR")
    	
    	' The Response.Write commands are used for debugging purposes..
    		
    	body = "This is an automated e-mail message.  Please DO NOT Reply." & chr(13)
    	body = body & "This Feedback was submitted on: "  & date & " at " & time & " by" & chr(13) & chr(13)
    	body = body & Request.Form("submitter_name") & chr(13)
    	body = body & Request.Form("submitter_title") & chr(13)
    	body = body & Request.Form("submitter_location") & chr(13)
    	body = body & "" & chr(13) & chr(13)
    	body = body & "Feedback - " & Request.Form("text_feedback") & chr(13)
    	body = body & chr(13)
    	body = body & "Refering URL: " & Request.Form("strReferingURL") & chr(13)
    		
    	
    	Set objMail = Server.CreateObject("CDONTS.NewMail")
    	objMail.From=" Web siteserver@yourcompany.com"
    	
    	'Check to see if MailTo info is blank. If it is blank then send it
    	'to the webmaster.
    	
    	If strMailTo = "" then
    		strMailTo = "webmaster@yourcompany.com"
    	End If
    	
    	' Used for Debugging.
    	'Response.Write "Mail To is: " & strMailTo
    	
    	objMail.To=Request.Form("Mailto")
    	objMail.Subject="Feedback Submitted By " & Request.Form("submitter_name")
    	objMail.Body=body
    	objMail.importance=1
    	objMail.Send
    	set objMail = Nothing
    %>
    <p align="center"><font color="#008080" size="5">Your feedback has been submitted.</font></p>
    <p align="center"><font color="#FF0000" size="5">Thank you for your feedback.<p>
    
    

    One of the first things to do is to make sure that the user is not coming to this page directly. I am doing this by looking at the text_feedback variable that is filled in on the feedback page. Again you can use a session variable to do this, or you can use another hidden HTML variable that would be on the feedback.asp page. Since users are coming to this page because they want to send some feedback, I am looking at the text_feedback variable. I use Response.Redirect to redirect them to the feedback.asp page if the text_feedback variable is blank.

    Next, the body of the message is assembled, and then the CDONTS COM object is called. The To, From, Subject, Body and Importance information is set, and then objmail.Send is used to send the e-mail. Finally, an HTML message is displayed thanking the user for their feedback.

    Final Thoughts

    This program uses several technologies that can be used over and over again in other ASP applications. I showed you how to send mail, read the URL Line, read input boxes, change how to cache a page, read a text file and read sever side variables. The code will need to be modified for you own specific e-mail address. And the location of the maillookup.txt file also needs to be changed.

    This article assumes you have the SMTP service installed that comes as part of the NT option pack.

    About the Author

    John DiGiovanni is a Senior Computer Analyst with Christiana Care Health Services in Wilmington, Delaware where he resides with his wife and 16-month old child. He programs in all of the latest Microsoft Technologies and has been programming in Active Server Pages since its inception. He has been programming since the age of 13 years old and is a Microsoft MCP, Novel CNE and Compaq ASE. He enjoys woodworking, technology and Amateur Radio (N3LUD). He may be reached at JDiGiovanni@ChristianaCare.org.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 5, 2000 - Point the Way with Graphics
    IImages may also be used via the ASP Request Object. This article will show you how the use the Request.Form("ImageName.X") property for such tasks as record navigation (e.g. << Record 1 of 15 >>) or column headings for HTML tables may use images rather than buttons. type = "SUBMIT") are the common mechanism to allow the user to request actions from your Web site. Images may also be used via the ASP Request Object. This article will show you how the use the Request.Form("ImageName.X") property for such tasks as record navigation (e.g. << Record 1 of 15 > >) or column headings for HTML tables may use images rather than buttons.
    [Read This Article]  [Top]
    Aug 5, 1999 - Writing ISQL_w in ASP
    In this article Christophe Berg show you how to build our own iSql with ASP and ADO 2.0. Using ASP you can build a database administration page that will allow you to modify your database from your browser. It’s both easy to implement and very useful, and it’s a good way to see how to work on a database with ASP.
    [Read This Article]  [Top]
    Jul 31, 1997 - Creating a Category Site with ASP
    In this issue 15 Seconds implements a catalog site that is build with Active Server pages and SQL Server. Along with the implementation there is source code and a discussion of the advantages and disadvantages of creating a catalog site that gets its content from a database. Included are pages for displaying products, creating a menu page, category page, and running a search across a database.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES