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:
02|If Request.Form("btnSend").Count > 0 Then
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")
16| <title>Send email with CDO</title>
19| <form name="sendEmail" action="EmailWithCDO.asp" method="post">
23| <td><input type="text" name="subject" /></td>
27| <td><input type="text" name="from" /></td>
30| <td>To: </td>
31| <td><input type="text" name="to" /></td>
34| <td valign="top">Message: </td>
35| <td><textarea name="message" rows="6" cols="30">
39| <td colspan="2"><input type="submit" name="btnSend"