Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Handling E-mail with HTML, CDO, and SMTP

How to play postmaster using Active Server Pages (ASP), Collaboration Data Objects for NT Server (CDONTS), and the Simple Mail Transfer Protocol (SMTP) service.

here are some mighty powerful e-mail solutions out there in network land. Just look at the size of Microsoft Exchange. But how about handling your intranet e-mail with something fast, light, cheap and flexible? In this two-part series, we’re going to show how to play postmaster using Active Server Pages (ASP), Collaboration Data Objects for NT Server (CDONTS) and the Simple Mail Transfer Protocol (SMTP) service. Remember: it all comes free with Windows NT 4.0.

In this first article we’ll walk through the configuration and verification of the Simple Mail Transfer Protocol service on Internet Information Server. We’ll show how to post an e-mail message from an HTML form and show you what the message looks like in the raw. In the second article we’ll show how to pull messages out of a mail folder and put them into an Access database or onto a Web page. Although this information is oriented towards an intranet application, the concepts apply Web-wide.

Configuring the Mail Service
Before going further, make sure that SMTP is installed with Internet Information Server 4.0. If SMTP wasn’t included in your original installation, run the Windows NT 4.0 Option Pack setup to add it.

Let’s say we’re working for Passable Computers ("Our Computers Aren’t Just Great, They’re Passable"). Your customer service requests on at Web form to go to the service department’s mailbox. Let’s go to Internet Information Server 4.0 and create an SMTP domain for Passable.

  1. Start the Internet Service Manager, by clicking Programs>Windows NT 4.0 Option Pack>Microsoft Internet Information Server>Internet Service Manager.
  2. In the Microsoft Management Console (MMC), expand the Internet Information Server node and expand the server name (P75). See Figure 1.
  3. Right click on Default SMTP Site.
  4. Click New and then click Domain.
  5. In the New Domain Wizard, make sure the domain type Local is selected and then click Next. See Figure 2.
  6. Type the name for the new mail domain, for instance passable.com. See Figure 3.
  7. Click Finish to return to the display

Having created the mail domain for passable.com, we need to configure the mail site to accept messages. Our task includes creating a directory where the mail will be dropped.

  1. In the MMC’s left-hand pane (also called the scope pane), click the Domains icon. The list of domains appears in the right-hand pane, as in Figure 4.
  2. In the right-hand pane, select the domain that you just created (passable.com), right-click and from the context menu, click Properties.
  3. We’re going to make passable.com the default local domain, so click Local and Default. Confirm the change if a dialog box appears.
  4. All messages go into the drop directory. In our case we’ll create a new directory to hold the messages by typing c:\Inetpub\Mailroot\passable.com. See Figure 5.
  5. Click OK to exit the properties page.
  6. Exit the MMC.

Configuring the Domain Name
Normally, passable.com would have its own domain name server (DNS) entry. But during development, let’s just configure one workstation to send mail to the mail drop box. Adding the server’s name and IP address to the Hosts file on your client Windows computer makes sure the client can find the SMTP site.

  1. Find the Hosts file (usually in c:\windows) and open the file in Notepad.
  2. Add an entry for the SMTP server’s IP address (e.g.,, a space, and the mail server’s alias (e.g., passable.com). See Figure 6.
  3. Save the Hosts file and exit Notepad.

Setting Up an HTML Form to Send E-mail
Now that you’ve mapped the IP address to the host (mail server) name we can dig into some ASP code. We need an HTML form to post on the Web server with the rest of Passable’s site. We fire up Visual InterDev and put together a barebones HTML form that will submit e-mail messages to service@passable.com. The following single page of code (response.asp)  does it all. It provides the form to submit the message, sends the e-mail and provides user feedback.

Notice the use of the CDONTS object in the VBScript code. CDO is another free component of IIS. The NewMail object is especially attractive for quick mailers like this one. The code here sets various message properties such as the recipient's name and message body. To make sure we don't lose the sender's friendly name, I've tacked it on to the Subject property. In the browser, the form looks like Figure 7.

<h1>Passable Computers Service</h1>
<p><em>Our service is Passable too!</em></p>
<% if request("formemail") = "" then%>
<form name="theform" method="POST" action="response.asp">
<p>Name: <input type="text" name="formname" size="20"></p>
<p>E-mail: <input type="text" name="formemail" size="20"></p>
<p>Message: <textarea rows="2" name="formmessage" cols="20"></textarea></p>
<p><input type="submit" value="Submit" name="B1"></p>
<p>We'll be in touch with you soon.</p>
<%Set myMail = CreateObject("CDONTS.NewMail")
myMail.From = request("formemail")
myMail.To = "service@passable.com"
myMail.Subject = "Service inquiry - " & request("formname")
myMail.Body = request("formmessage")
Set myMail = Nothing
end if

Peering into the SMTP Mailbox
Let’s confirm that our e-mail message to service@passable.com arrived at the SMTP server. We need to peer into a file directory on the Web server.

  1. On the Web server, open Windows Explorer and navigate to C:\Inetpub\Mailroot\passable.com. See Figure 8.
  2. In Notepad, open the file that has the extension .EML.

When you look at the following text, you see that there’s more than meets the eye. In your mail reader, this is a one-liner. Clearly, there’s a lot of overhead in an e-mail message.

x-sender: ken_cox@msn.com
x-receiver: service@passable.com
Received: from mail pickup service by p75.winnt with Microsoft SMTPSVC;
Tue, 7 Jul 1998 22:45:09 -0400
From: <ken_cox@msn.com>

To: service@passable.com
Subject: Service inquiry - Ken Cox
Date: Tue, 7 Jul 1998 22:45:08 -0400
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Message-ID: 000600945020878P75@p75.winnt
Please send a service contract.

In this first article, we’ve set up the basic SMTP e-mail system for our intranet. We’ve configured the server, created a directory to receive the e-mail, set up the HTML form to send messages to our mail site and we’ve seen what the mail message looks like in its raw form.

In the next article, we’ll use Active Server Pages code to retrieve the mail from the mailbox and put the contents, subject and sender information into an Access database as well as on a Web page. The techniques for manipulating e-mail open up many possibilities for managing messages and automating replies.

Rama Ramachandran is the Vice President of Technology with Imperium Solutions and is a Microsoft Certified Solution Developer and Site Builder. He has extensive experience with building database systems and has co-authored several books including "Professional Visual InterDev 6 Programming" and "Professional Data Access" (Wrox). Rama teaches Visual Basic and Web development at Fairfield University and University of Connecticut.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date