JMail
Examples & Implementations

Let's start with working examples of three commonly used features:
  1. Feedback Form
  2. Recommend to a Friend
  3. 404 Error Report

The main idea in of these three examples is to send email from the ASP script. There are no built-in capabilities to send email from ASP, but there are lots of free and commercial components enabling you to do this.

I will be using the JMail Component (JMail Component Reference) that is available for free from http://www.dimac.net/. You may use any other component available on your host. It shouldn't be difficult to adapt these examples to work on your site.

Feedback Form

One of the most important elements of a great site is the ability to satisfy user needs, and the easiest way to know what your users need and want is by getting their feedback. Displaying your contact information doesn't guarantee much feedback. There are a variety of reasons why people might not send you email even if they want to tell you something:

  • they're not browsing your site from their own computer
  • they don't have their email software properly configured
  • an email message tends to require some formal things like greetings and more
  • they don't want to give you their email but still have something important to say...

Having a feedback form solves most of these problems, enabling you to get more information from your users and build a better site.

Implementation of feedback form in ASP is quite easy:

  1. create HTML form,
  2. get fields, and
  3. send email

So let's start by creating basic a <FORM>

<FORM METHOD="POST" ACTION="jmail.asp">
    Name:<INPUT TYPE="TEXT" NAME="fromName"><BR>
    Email:<INPUT TYPE="TEXT" NAME="fromAddr"><BR>
    Subject:<INPUT TYPE="TEXT" NAME="subject"><BR>
    Message:<TEXTAREA NAME="body"></TEXTAREA><BR>
    <INPUT TYPE="SUBMIT" VALUE="Send"><INPUT TYPE="RESET" VALUE="Clear">
</FORM>

And now we will get the fields from that Form and send them to our email:

<%
var jmail = Server.CreateObject("jmail.smtpmail");
jmail.ServerAddress = "mail.company.com";
jmail.AddRecipient("webmaster@company.com");
jmail.Sender = Request("fromAddr");
jmail.SenderName = Request("fromName");
jmail.Subject = Request("subject");
jmail.Body = Request("body");
jmail.Execute();
%>

This is the simplest implementation of a Feedback Form. You probably need to customize it to be more universal. You can make the Form accept not only the Name and Email of the Sender, Subject and Body, but also allow a choice of Email Address of the Recipient (you or appropriate person) so you may use it from various parts of your site or on various sites. In this manner, you will be able to add a select box (dropdown) to your HTML form, so your visitor may choose the theme of the message and send the message to a specific responsible person. To be even more universal, you may want the script to redirect to a specific "thank you" page after processing.

Now our HTML form will look something like this:

<FORM METHOD="POST" ACTION="jmail.asp">
    <INPUT TYPE="HIDDEN" NAME="redir" VALUE="/index.htm">
    Name:<INPUT TYPE="TEXT" NAME="fromName"><BR>
    Email:<INPUT TYPE="TEXT" NAME="fromAddr"><BR>
    Theme:
    <SELECT NAME="toAddr">
        <OPTION VALUE="sales@company.com">Product sales
        <OPTION VALUE="webmaster@company.com">Bugs, dead links, etc.
     </SELECT><BR>
     Subject: <INPUT TYPE="TEXT" NAME="subject"<BR>
    Message:<TEXTAREA NAME="body"></TEXTAREA><BR>
    <INPUT TYPE="SUBMIT" VALUE="Send"><INPUT TYPE="RESET" VALUE="Clear">
</FORM>

And the processing script:

<%
var jmail = Server.CreateObject("jmail.smtpmail");
jmail.ServerAddress = "mail.company.com";
jmail.AddRecipient(Request("toAddr"));
jmail.Sender = Request("fromAddr");
jmail.SenderName = Request("fromName");
jmail.Subject = Request("subject");
jmail.Body = Request("body");
jmail.Execute();
Response.Redirect(Request("redir"));
%>

Note: Response.Redirect() should be used before any content has been passed to the client.

Recommend To a Friend

Now that you've finally build a really useful site you need to start building traffic. One of the most powerful ways of attracting new visitors is a Recommendation from someone they know and trust -- a friend. But no matter how good your site is, people are often still too hurried (or lazy) to start their mailer and send some recommendations to their friends. This feature allows your satisfied visitor to recommend your site to a friend without:

  • having to do something extraordinary
  • without leaving your site

He/she just fills in his/her Name and Email Address, Name and Email Address of the friend and click a button.

The implementation of this feature is not much different from the implementation of the Feedback Form. Just collect the needed information and send the email.

<FORM METHOD="POST" ACTION="recommend.asp">
    Your name:<INPUT TYPE="TEXT" NAME="fromName"><BR>
    Your email:<INPUT TYPE="TEXT" NAME="fromAddr"><BR>
    Friends name:<INPUT TYPE="TEXT" NAME="toName"><BR>
    Friends email:<INPUT TYPE="TEXT" NAME="toAddr"><BR>
    <INPUT TYPE="SUBMIT" VALUE="Send"><INPUT TYPE="RESET" VALUE="Clear">
</FORM>

And the processing script (recommend.asp):

<%
var jmail = Server.CreateObject("jmail.smtpmail");
jmail.ServerAddress = "mail.company.com";
jmail.AddRecipient(Request("toAddr"), Request("toName"));
jmail.Sender = Request("fromAddr");
jmail.SenderName = Request("fromName");
jmail.Body = "Dear " + Request("toName") + " \n\n" +
Request("fromName") + " recommends you to visit " +
"Company site at http://www.company.com/. " +
"We have lots of useful information.";
jmail.Execute();
%>

You may want to allow for additional text to be added by the visitor, but weigh the fact that this could potentially be used to send inappropriate mail from your Website.

404 Error or Problem Report

The site now has a lot of traffic and you've submitted to lots of search engine and indexes, and there are finally other sites linking to yours. Inevitably there will be some bad links among all those. When a browser requests a non-existent page from your Webserver, it receives 404 "page not found" error. Many servers can be configured to display a customized error page to be shown to your wayward visitor. You may use this page to let the visitor know that the page he requested doesn't exist and ask him to report the problem to the Webmaster of the site he came from. Now, how many of the visitors will actually do that? I would guess that the number is not much greater than 0.

You could analyze your log files to find out where are the bad requests are coming from, but when you have a high-traffic site, downloading and analyzing these log files can be a quite a chore. The easiest and fastest way is to make the error page to send you email with referrer and error information. To accomplish this, just add few lines of code to your custom 404 page:

<%
var jmail = Server.CreateObject("jmail.smtpmail");
jmail.ServerAddress = "mail.company.com";
jmail.AddRecipient("webmaster@company.com");
jmail.Sender = "badlinkreporter@company.com";
jmail.Subject = "Bad Link Report";
jmail.Body = "Bad link to our site at " +
Request.ServerVariables("HTTP_REFERER");
jmail.Execute();
%>

Conclusion

By adding these three simple features described above, you can spice up your site and make it more powerful. It's important to remember, however, that it's not the latest and greatest bells and whistles make your site sell but high quality content. So while adding new tools and features to your site, don't forget about creating new interesting content -- it's the main reason why users visit for the first time and why they return later.