IIS Answers tm                                                                                          
Support Central for Internet Information Server 4 and 5   

IIS Answers - Top 10 FAQ
How to Use CDONTS to Send Mail

Ultimate IIS
hands-on, fast track, up-to-date training on IIS 4 and 5

IIS Lists
moderated email discussions on IIS related topics

About Brett Hill

Contact Information

IIS Administrator Newsletter
published by Windows 2000 magazine. See IIS Informant articles.

Colloborative Data Objects for NT (CDONTS.DLL) is a built in set of objects that permit you to easily send mail using ASP. To use it requires that the SMTP server be up an running. Also, you can have problems if your ASP application is running out of process. Otherwise, it's very straightforward.

CDONTS makes use of the SMTP server on IIS. As a result, it is quite an effective delivery system with adjustable settings for number of retries etc. via the SMTP MMC.

Here's how it's done:

<% Set mymailobject = CreateObject("CDONTS.Newmail")
mymailobject.From = "me@myisp.com"
mymailobject.To = "you@yourisp.com"
mymailobject.Subject = "This CDONTS thing is dang easy!"
mymailobject.Body = "See www.iisanswers.com for a quick lesson." %>

To send multiple lines for the body, just concatenate strings together:

bodytext = "Hi, this is my message and I wanted to "
bodytext = bodytext & "send more than one line."

Then you set mymailobject.Body = bodytext

You can also designate multiple receipients by separating the addresses with semilcolons as follows:

mymailobject.to = "first@x.com;second@y.com;third@z.com"

That assigns content to all the usual variables. All that's left is to send the message:

<% mymailobject.Send
set mymailobject = Nothing %>

And it's off to SMTP land. I like it when it's easy.

You can also specify CC (object.CC) BCC (object.BCC) and even send attachments.

There are some built in constants in CDONTS that if used offer a bit more flexibility. Features like HTML support in the body for example. These constants all start with cdo (such as cdoBodyFormatHTML). There is no include file provided to declare these constants but lucky for us, there is a KB article that is helpful.

You can see that with CDONTS and ASP, you can basically invent any kind of mailing system you wish for sending order confirmations, newsletters, messages to list servers to subscribe or unsubscribe members, etc. One creative use is to customize error pages and have them automatically fire off a message to alert admins of a potential problem.

Where CDONTS really excels is in sending one of a kind messages from forms like order confirmations, sending people their forgotten passwords, shooting off a message to the webmaster, etc. Much nicer than a mailto: tag that relies on the client's setup.

Update: If you use Windows XP or .net Server, you will find that CDONTS is doesn't work. This is because Microsoft no longer supports CDONTS in favor of the CDOSYS.