+1 480-998-1843
info@commkal.com
Hosting Solutions
WINDOWS SERVER HOST

Help Options



E-Mail
FAQ
Links

FTP
FAQ
Links

FrontPage
FAQ
Links

HTML
FAQ
Links

ASP How-To
Cool Things to do With JMail

J-Mail allows you to easily send any kind of information from your web page to any e-mail address via SMTP. Full documentation on JMail's features are available at http://tech.dimac.net.

In this tutorial we will be going over the steps necessary to complete the following goals:

  1. Request information from a visitor on our web site.
  2. Use ASP to store that information
  3. Send the "stored" information to an e-mail address.
This tutorial is of medium difficulty, but with a little experimentation, anyone familiar with HTML should be able to master this technique.

Step One
Let's say that we want to get information from visitors to our web site. To keep things simple, we'll only ask two questions: their name and e-mail address. To do this, we'll create a form that asks those very questions. The code for this is demonstrated below.

<html>
<head>
<title>Question Page</title>
</head>
<body>
<form method="post" action="sendit.asp">
What is your name?
<input type="text" name="name" size="25">
What is your e-mail address?
<input type="text" name="email" size="25">
<INPUT type="reset" value="RESET">
<INPUT type="submit" value="SUBMIT">
</body>
</html>

Name that page "question.html" and save it.
Let's examine that page before we move on to the second part of our guide. The first major part of our page is the form. There we ask the two questions and name their values as "name" and "email" Notice that we are posting the information in the form to a new page called "sendit.asp" when they click on the submit button. So far, we haven't used any ASP at all. Nor will we on the first page. The second page is where all the magic happens...

Step Two
Ok, let's create a new page called "sendit.asp". Notice that the file doesn't have the extension ".html". This is because we need the server to process special ASP instructions that we will be using. The ".ASP" extension is how the server can tell which pages have code on them so it knows to look at and process the code we will be using. Let's look at the source for this new page in sections.

<html>
<head>
<title>Answer Page</title>
</head>
<body>

Let's assign the values from the form on the previous page to some ASP variables. We will be using session variables which means that the variables values will last from page to page, unlike local variables. Although we don't have any more pages after this one, using session variables gives you more flexability with your own implentation of this component.

<%
Session("strName") = Request.Form("name")
Session("strEmail") = Request.Form("email")
%>

What did we just do? Basically, we took the values from the form on the question page and assigned them to ASP variables. Keep in mind that the variable names are case sensitive.
Now let's e-mail these variables to "bob@somewhere.com" You would obvisouly use whatever e-mail address was applicable to you here.

We start ASP code...
<%

Leave this code the same.

Set JMail = Server.CreateObject("JMail.SMTPMail")

This is the name of your SMTP server followed by the port number. (usually port 25)

JMail.ServerAddress = "mail.domain.com:25"

Set the reply-to address of this e-mail.

JMail.Sender = "replyaddress@domain.com"

Set the subject of this e-mail. JMail.Subject = "Insert Subject Here"

This is who the e-mail will be sent to.

JMail.AddRecipient "jim@chrisandjim.com"

You can add recipients by adding the line(s) below. Notice in the line below, we are using the variable that we just set as a recipient value. This means that the e-mail will also be sent to whatever e-mail address the visitor typed in on the form on our previous page.

JMail.AddRecipient Session("strEmail")

This is where you put the body of the message that you want to send. We are going to put the values of the questions from our form on the previous page.

Write the word "Name: "

JMail.Body = "Name: "

To add more information to the body, we use the following command. You can use it as many times as you want. In the case below, we are displaying the value of the variable that we set above. JMail.AppendText Session("strName") & vbCrLf

Repeat process for the email value.

JMail.AppendText "Email: " & vbCrLf
JMail.AppendText Session("strEmail") & vbCrLf

For e-mail readers that support it, you can use this setting to adjust the priority of the message.
1 - highest priority (Urgent)
3 - normal
5 - lowest

JMail.Priority = 1

Here the last ASP command. This sends the e-mail!

JMail.Execute

End of our ASP code

%>
</body>
</html>

That's it. I am sure that you can see many uses for this script on your site. It can be used to serve a variety of purposes. We only went over the down and dirty method of using JMail in a real-world example. However, if you want to harness the full power of JMail and see mroe examples, visit http://tech.dimac.net.

Copyright 1998-2024 Communiqué Kaleidoscope, Inc.