In This Site

Home
Free News Updates
Using Microsoft FrontPage
Cascading Style Sheets
Database Fundamentals
FrontPage & Access
FrontPage Navigation
Website Security
Solving Problems
Learning SQL
Code Samples
Promote Your Site

In This Section

Up
CDONTS
Database Connections
Add to Database
Database & Email

The number one source  for making your website sell!

 

Sending Email Using the CDONTS Object

While Microsoft FrontPage DOES allow you to send form results by email, it does offer only limited capabilities in this area. You can only send form results to a single email address and your ability to format the message is very limited.

To make things worse, you cannot send your data to an email address AND a database file. You can't create a page to display database details AND send that data along to an email address.

While Microsoft FrontPage makes the basic form functions a breeze, there WILL come a time when you need something a little more powerful.

Well here it comes.

If your server is hosted on Microsoft Internet Information Server (IIS), then you already have a very powerful tool called CDONTS. This amazing tool offers almost unlimited email capability and it's also FREE which adds to its popularity. The term CDONTS is an abbreviation of "Collaboration Data Objects for Windows NT Server".

The process involves several steps
  1. Introduction to CDONTS
  2. Properties of a CDONTS Message
  3. Send a Basic Message

  4. Send a Message to Multiple Recipients

CDONTS will let you add email functionality to ANY of your active server or Database Results Wizard pages. That's the good news. The bad news is that you WILL need to learn to write some code to accomplish these tasks.

I know, I feel your pain. This is an ADVANCED topic and should only be attempted once you have mastered the basic tools that come with FrontPage. If you are comfortable creating forms that will be sent to a database or an email address, then you're ready to tackle this project.

As a fellow non-programmer, I struggled with this one. I posted numerous messages on discussion forums and begged the true experts for the simplest way of accomplishing these functions. The results of this extensive amount of groveling are gradually becoming available here.

As you tackle these projects, don't YOU be too proud to beg. While we don't have the resources to help each of our millions of readers (OK, so I'm a bit optimistic), there are many FrontPage focused discussion forums that exist for that sole reason. 

Introduction to CDONTS

CDONTS is like a magic pill that web developers eventually need to take. It tastes bitter, but it provides those willing to swallow it with almost mystical powers.

Need to send a form to a database AND and email address - Shazam - no problem. Want to send a form to multiple email addresses - poof - off it goes. Want to display some database records on a form and THEN send that form to your customer service department - easy as pie.

First we'll look at the code required to send a simple pre-written email to a specific address. This is code that you could place on any ASP page. Your reasons for sending an email can be endless, but the method of sending a basic email are always the same.

Here are the steps:

  1. Declare variables to hold the various aspects of your email message.
  2. Tell the server to create a new instance of the NewMail object
  3. Compose the message for the body of your email message
  4. Tell the NewMail Object who to send the message to, what to place in the subject line, the priority level, and the mail format.
  5. Send the message
  6. Free up the memory by setting the SendMail object to nothing.

Does that sound manageable. In the next section, we'll go through the steps one-by-one and walk you through a simple asp page that will send an email message.

Properties of a CDONTS Message

Every CDONTS email message contains some of the following properties. Some of the properties are optional. We will not use these until we get to our more complicated tutorials later on in this section. To begin with, we'll keep things as simple as possible.

Property Description
From identifies the person sending the message
To identifies who will receive the message. You can list multiple email addresses separated by a semi-colon ;
Cc (Optional) identifies who you would like to receive a carbon copy of the message
Bcc (Optional) identifies who you would like to receive a blind carbon copy of the message. Blind carbon copy recipients ARE NOT visible to the person receiving the message.
Importance (Optional) Lists the priority of the message. It uses a numeric value in the following format: Low (0), Normal (1) or High (2). The default is Normal.
BodyFormat (Optional) You can send your message in either plain text OR HTML format. It uses a numeric value of 0 for HTML or 1 for plain text (default).
MailFormat (Optional) You can decide if you want your message in MIME format (0) or plain text (default - 1)
AttachFile (Optional) If you want to attach a file that is already on your server, you can use this method to attach the file.
AttachURL (Optional) If you would like to attach a file and attach a url to the file location, use this method.
Send Send the message
Send a Basic Email Message

This code could be placed on any asp page to send a message. The first example shows a single line message that will go to a single email address.

The following tutorial will walk you through the various lines necessary to create a basic message. Later, we'll put them all together to show you the final executable code. All of our script code will be indented to the right to help it stand out from the descriptive text.

To begin with, we need to indicate that we are beginning an executable script. For asp pages, all scripts begin with the <% symbol and end with %>.

<%

Now, declare our email variable as MyMail. If you read other tutorials, you'll see variations of this such as MyCDOMail or MyCDONTSMail. You can choose to call it anything you wish.

Dim MyMail

The next step is to create a new instance of the CDONTS New Mail object. The following line will use the variable name that you created in the previous step.

Set MyMail = CreateObject("CDONTS.NewMail")

The next two lines describe who you want to send the message to and who it will appear to have come from.

MyMail.From= "cdont@nobody.com"
MyMail.To= "sample@nobody.com"

What would you like your subject line to read?

MyMail.Subject="This is a Test"

Now for the body of this message, we'll keep it simple and enter just a single line message.

MyMail.Body = "Thank you for ordering that stuff"

Time to send the message

MyMail.Send

The message has been sent. It's now time to free up the memory that the New Mail object was using. We do this by setting it to equal nothing.

set MyMail=nothing

OK, we're finished, so we can use the end script symbol.

%>

OK, let's put it all together. Open a blank page in FrontPage and switch to the HTML pane. Copy the following text and paste it into a blank document in Notepad (or any other text editor). Then, copy the material from your text editor and paste it into your FrontPage document. You need to paste it above the first <HTML> tag.


<%
Dim MyMail
Set MyMail = CreateObject("CDONTS.NewMail")
MyMail.From= "cdont@nobody.com"
MyMail.To= "sample@nobody.com"

MyMail.Subject="This is a Test"
MyMail.Body = "Thank you for ordering that stuff"
MyMail.Send
set MyMail=nothing
%>

 

Sending Your Email to Multiple Recipients

Now, let's alter the code to send an email two two recipients, with a carbon copy going to a third. I'll highlight the changes in yellow.

To add additional recipients, just separate the addresses with a semi-colon (;). Be sure to do this within the original set of double brackets. For instance, to send a message to two recipients, the syntax is:

MyMail.To = "Address1;Address2"

I made the mistake of trying to use the following syntax and it resulted in an error message:

MyMail.To = "Address1" ; "Address2"

Now, to add a line for the carbon copy recipient, be sure to use a capital C followed by a lower case c (Cc). It should look like:

MyMail.Cc = "Address"

<%
Dim MyMail
Set MyMail = CreateObject("CDONTS.NewMail")
MyMail.From= "cdont@nobody.com"
MyMail.To= "sample@nobody.com;sample2@nobody.com"

MyMail.Cc="cc@nobody.com"

MyMail.Subject="This is a Test"
MyMail.Body = "Thank you for ordering that stuff"
MyMail.Send
set MyMail=nothing
%>

Are you beginning to get the hang of this?

If you want to have the body of your message be more than one line long, end each line with the following:

& chr(13)

Then begin the next line with:

 MyMail.Body=MyMail.Body &.

The above example would change to the following:

<%
Dim MyMail
Set MyMail = CreateObject("CDONTS.NewMail")
MyMail.From= "cdont@nobody.com"
MyMail.To= "sample@nobody.com;sample2@nobody.com"

MyMail.Cc="cc@nobody.com"

MyMail.Subject="This is a Test"
MyMail.Body = "Thank you for ordering that stuff" & chr(13)

MyMail.Body=MyMail.Body & "Your Order is On The Way."
MyMail.Send
set MyMail=nothing
%>

In our next tutorial, I'll show you how to use FrontPage forms to populate your email message.


These tutorials are part of an upcoming training course called "FrontPage Magic - How To Create A Database Driven Website For Non-Programmers". Stay tuned for more details on this exciting new product.

Send your tips to .
All materials Copyright © Ward Cameron All Rights Reserved