日期:2008-12-17  浏览次数:20860 次

Introduction

CDONTS was actually replaced by CDO already in Windows 2000 and Windows XP. But these Operating Systems supported CDONTS, and you could use CDONTS. Windows Server 2003 does not support CDONTS, and we are forced to use CDO. This tutorial is a crash course in CDO, and we will create a few simple web forms for sending emails with CDO and ASP.

Before we begin

Before I show you any code, there are a few things we must do to get this to work. The first thing is set up a web server – IIS 6.0. You can start the wizard for the installation of IIS 6.0 from Manage Your Server (Start->Programs->Administrative Tools->Manage Your Server).

Click Add or remove a role.
Select Application Server
You do not need ASP.NET nor FrontPage Server Extensions for this tutorial
But that is not enough; we also need the SMTP server to send our emails, though I will also show you how to use a remote server instead of the local. So, open up Add or Remove Programs from the Control Panel.

Click Add/Remove Windows Applications
Highlight Application Server, and click Details
Highlight Internet Information Services (IIS) and click Details
Select SMTP Service and click OK, and finally Next
We are almost ready for the code writing now, but since IIS 6.0 is locked down by default, we have to go to the Internet Information Services Manager (Start->Program->Administrative Tools) and enable the ASP extension.

When the IIS Manager has started, click on Web Service Extensions in the left pane.
Select Active Server Pages, and click on Allow

That’s it! We are now ready for the fun part, the coding!

A simple text email

So, start your favorite text editor, and type this:

01|<%
02|If Request.Form("btnSend").Count > 0 Then
03|
04|   Set objMessage = CreateObject("CDO.Message")
05|   objMessage.Subject = Request.Form("subject")
06|   objMessage.Sender = Request.Form("From")
07|   objMessage.To = Request.Form("To")
08|   objMessage.TextBody = Request.Form("message")
09|   objMessage.Send
10|   Response.Redirect("Sent.HTML")
11|End If
12|%>
13|
14|<HTML>
15|   <head>
16|      <title>Send email with CDO</title>
17|   </head>
18|   <body>
19|      <form name="sendEmail" action="EmailWithCDO.ASP" method="post">
20|         <table>
21|            <tr>
22|               <td>Subject:</td>
23|               <td><input type="text" name="subject" /></td>
24|            </tr>
25|            <tr>
26|               <td>From:</td>
27|               <td><input type="text" name="from" /></td>
28|            </tr>
29|            <tr>
30|               <td>To: </td>
31|