2:22 pm Saturday, July 05, 2008


  Navigation
  Help?
Contact Aaron for all inquiries.
 

  News

ASP Inline Calendar 3.9 Beta 1
ASP Games
ASP Inline Corporate Calendar 3.8 BETA 1 Demo
Calendar Updates
 

A Better World By Design
 
  CDONTS Tutorial
AaronOutpost : ASP / Tutorials / Email Using CDONTS

CDONTS Tutorial
By: Aaron B. Copyright AaronOutpost.com

CDONTS stands for 'Collaboration Data Objects for Windows NT Server'
The
CDONTS component is installed when you install IIS on NT4, Windows 2000, & Windows XP.

 
Download
Examples

Download has 4 working examples of CDONTS E-mail Form's which you can use.

This tutorial concentrates on the CDONTS NewMail object uses to format and then send the e-mail and not the HTML and JavaScript details of collecting the information. I may write those in the future. For purposes right now, just use the details and study them. HTML and JavaScript is pretty simple.

IMPORTANT WINDOWS XP WITH IIS 5.1 INFO
CDONTS component will run on Windows XP, However Microsoft removed the component from IIS 5.1 on Windows XP, so you need a copy of the cdonts.dll and register it on the IIS web server.

To use this component to send e-mail you also need the SMTP Server (installed by default with IIS 4 & 5), or Microsoft Exchange installed on the web server.

 

 

Creating the Code

This page I am creating below is the send_email.asp mailing component page as seen in the download.

First we need to dimension some variables to get this show on the road.

In theory what you will want to create is an HTML page with a form to collect information and then submit it as seen as default.html in the examples available for download. So, on your own send_mail.asp you will want to dimension more variables to hold the information from the form.

In this case I am only going to dimension one variable to hold the NewMail Object

<%
'Dimension variables needed
Dim
cdonts_MailObj      'Holds the CDONTS NewMail Object


 

Next we need to create "CDONTS NewMail" object on the server.

'Create e-mail server object using CDONTS.NewMail
Set
cdonts_MailObj = Server.CreateObject("CDONTS.NewMail")


 

Now we need to construct the email since we have a NewMail object

From property is required! It allows the recipient know who the email is from.

'Who the e-mail is being sent from
cdonts_MailObj.From = "SenderE-mail@MyDomain.com"


 

Now set the recipients (people receiving the email) using the To property.

'Who the e-mail is to be sent to
cdonts_MailObj.To = "Recipient@theirDomain.com"


 

Property Cc holds e-mail addresses you wish to send Carbon Copies of the e-mail.

You list multiple recipients by separating them with either a comma (,) or a semicolon (;)

This property can be left out.

'Who the carbon copies are sent to
cdonts_MailObj.Cc = "Friend1@theirDomain.com;Friend2@anotherDomain.com"


 

The Bcc property is the  Blind Copies list which is formatted the same as Cc.

Again you can leave this property out.

'Who the blind copies are sent to
cdonts_MailObj.Bcc = "BlindCopyRecipient1@theirDomain.com;BlindCopyRecipient2@anotherDomain.com"


 

Subject property, self explanatory

'Set the subject of the e-mail
cdonts_MailObj.Subject = "Message Sent from my CDONTS Page"


 

You can also change the formatting of the email using BodyFormat property. The default is Text.

0 = HTML
1
= Text

If you leave this property out the e-mail will be sent as plain text format.

'Set the format of e-mail body ( 0=HTML 1=Text )
cdonts_MailObj.BodyFormat = 0


 

If you set BodyFormat to HTML then you need to set the MailFormat property to MIME.

0 = MIME
1
= Text.

The default is text so you can leave this property out if you are just sending text emails.

'Set mail format ( 0=MIME 1=Text )
cdonts_MailObj.MailFormat = 0


 

The Body property holds the message of the email.

Depending on whether or not you allow HTML and MIME is whether or not you can use HTML in the body. I have them enabled so I included HTML in my body of the email displayed below.

If HTML is not turned on, HTML codes will appear as text.

'Main Body of Email
cdonts_MailObj.Body  = "<h2>Hello</h2><br><b>This is my e-mail in HTML format</b>"


 

Importance property tells the mail messaging system when to schedule delivery of the e-mail.

0 - Low, sent during times of low system use
1 - Normal
, sent at regular delivery times (Default)
2 - High
, the system will try to send immediately.

'Importance of the e-mail (0=Low, 1=Normal, 2=High)
cdonts_MailObj.Importance = 1


 

Now, lets send it! Using the Send property.

'Send the e-mail
cdonts_MailObj.Send


 

Finally once the e-mail has been sent we can close the server object releasing server resources.

'Close the server object
Set
cdonts_MailObj = Nothing
%>


 

The Finished Project!

There are other properties of the CDONTS NewMail  object but those are the most common and useful for most common use.

<%
'Dimension variables needed
Dim
cdonts_MailObj      'Holds the CDONTS NewMail Object

'Create e-mail server object using CDONTS.NewMail
Set
cdonts_MailObj = Server.CreateObject("CDONTS.NewMail")

'Who the e-mail is being sent from
cdonts_MailObj.From = "SenderE-mail@MyDomain.com"

'Who the e-mail is to be sent to
cdonts_MailObj.To = "Recipient@theirDomain.com"

'Who the carbon copies are sent to
cdonts_MailObj.Cc = "Friend1@theirDomain.com;Friend2@anotherDomain.com"

'Who the blind copies are sent to
cdonts_MailObj.Bcc = "BlindCopyRecipient1@theirDomain.com;BlindCopyRecipient2@anotherDomain.com"

'Set the subject of the e-mail
cdonts_MailObj.Subject = "Message Sent from my CDONTS Page"

'Set the format of e-mail body ( 0=HTML 1=Text )
cdonts_MailObj.BodyFormat = 0

'Set mail format ( 0=MIME 1=Text )
cdonts_MailObj.MailFormat = 0

'Main Body of Email
cdonts_MailObj.Body = "<h2>Hello</h2><br><b>This is my e-mail in HTML format</b>"

'Importance of the e-mail (0=Low, 1=Normal, 2=High)
cdonts_MailObj.Importance = 1

'Send the e-mail
cdonts_MailObj.Send

'Close the server object
Set
cdonts_MailObj = Nothing
%>

 


AaronOutpost : ASP / Tutorials / Email Using CDONTS



Aaron Outpost West Virginia, USA A Mark of _-Squire-_ Creations Inc.  CopyrightŠ 2005 All Rights Reserved